-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(history): Reset history.current when all apps are destroyed #3298
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b8dad60
feat(history): Reset history.current when all apps are destroyed
nightnei c779bbc
test(history): adding restart-app test
nightnei cac3e2c
refactor: split History.teardown method
nightnei b95e670
refactor: general History.teardown method
nightnei File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import Vue from 'vue' | ||
import VueRouter from 'vue-router' | ||
|
||
const Home = { template: '<div>home</div>' } | ||
const Foo = { template: '<div>foo</div>' } | ||
|
||
const routes = [ | ||
{ path: '/', component: Home }, | ||
{ path: '/foo', component: Foo } | ||
] | ||
|
||
const router = new VueRouter({ | ||
mode: 'history', | ||
base: __dirname, | ||
routes | ||
}) | ||
|
||
// track number of beforeResolve | ||
const increment = name => { | ||
const counter = document.getElementById(name) | ||
counter.innerHTML++ | ||
} | ||
|
||
document.getElementById('beforeEach').innerHTML = 0 | ||
router.beforeEach((to, from, next) => { | ||
increment('beforeEach') | ||
next() | ||
}) | ||
|
||
document.getElementById('beforeResolve').innerHTML = 0 | ||
router.beforeResolve((to, from, next) => { | ||
increment('beforeResolve') | ||
next() | ||
}) | ||
|
||
document.getElementById('afterEach').innerHTML = 0 | ||
router.afterEach((to, from) => { | ||
increment('afterEach') | ||
}) | ||
|
||
Vue.use(VueRouter) | ||
|
||
let vueInstance | ||
const mountEl = document.getElementById('mount') | ||
const unmountEl = document.getElementById('unmount') | ||
|
||
mountEl.addEventListener('click', () => { | ||
vueInstance = new Vue({ | ||
router, | ||
template: ` | ||
<div id="app"> | ||
<h1>Hello "Restart-app"</h1> | ||
<ul> | ||
<li><router-link to="/">Go to Home</router-link></li> | ||
<li><router-link to="/foo">Go to Foo</router-link></li> | ||
</ul> | ||
<router-view id="view"></router-view> | ||
</div> | ||
` | ||
}).$mount('#app') | ||
}) | ||
|
||
unmountEl.addEventListener('click', () => { | ||
vueInstance.$destroy() | ||
vueInstance.$el.innerHTML = '' | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<!DOCTYPE html> | ||
<link rel="stylesheet" href="/global.css"> | ||
<a href="/">← Examples index</a> | ||
|
||
<hr /> | ||
|
||
<button id="mount">mount</button> | ||
<button id="unmount">unmount</button> | ||
|
||
<hr /> | ||
|
||
Count beforeEach: <span id="beforeEach"></span><br /> | ||
Count beforeResolve: <span id="beforeResolve"></span><br /> | ||
Count afterEach: <span id="afterEach"></span><br /> | ||
|
||
<hr /> | ||
|
||
<div id="app"></div> | ||
|
||
<script src="/__build__/shared.chunk.js"></script> | ||
<script src="/__build__/restart-app.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const bsStatus = require('../browserstack-send-status') | ||
|
||
module.exports = { | ||
...bsStatus(), | ||
|
||
'@tags': ['history'], | ||
|
||
basic: function (browser) { | ||
browser | ||
.url('http://localhost:8080/restart-app/') | ||
.waitForElementVisible('#mount', 1000) | ||
.assert.containsText('#beforeEach', '0') | ||
.assert.containsText('#beforeResolve', '0') | ||
.assert.containsText('#afterEach', '0') | ||
|
||
// Mounting will trigger hooks | ||
.click('#mount') | ||
.waitForElementVisible('#app > *', 1000) | ||
.assert.containsText('#beforeEach', '1') | ||
.assert.containsText('#beforeResolve', '1') | ||
.assert.containsText('#afterEach', '1') | ||
.assert.containsText('#view', 'home') | ||
|
||
// Navigate to foo route will trigger hooks | ||
.click('#app li:nth-child(2) a') | ||
.assert.containsText('#beforeEach', '2') | ||
.assert.containsText('#beforeResolve', '2') | ||
.assert.containsText('#afterEach', '2') | ||
.assert.containsText('#view', 'foo') | ||
|
||
// Unmount | ||
.click('#unmount') | ||
.assert.containsText('#app', '') | ||
|
||
// Second mounting will trigger hooks | ||
.click('#mount') | ||
.waitForElementVisible('#app > *', 1000) | ||
.assert.containsText('#beforeEach', '3') | ||
.assert.containsText('#beforeResolve', '3') | ||
.assert.containsText('#afterEach', '3') | ||
.assert.containsText('#view', 'foo') | ||
|
||
.end() | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we rename this method, it might make sense to rename the
setupListeners
method, too.vue-router/src/history/base.js
Line 251 in dfc2892