}
const Foo = createTestComponent('Foo')
-const Bar = createTestComponent('Bar')
const One = createTestComponent('One')
const Two = createTestComponent('Two')
const Aux = createTestComponent('Aux')
+const WithId = defineComponent({
+ template: `<p :id="'with-id-' + $route.params.id">id: {{ $route.params.id }}</p>`,
+})
+
const webHistory = createWebHistory('/guards-instances')
const router = createRouter({
history: webHistory,
// TODO: test that the onBeforeRouteUpdate isn't kept
{
path: '/b/:id',
- component: Bar,
+ name: 'id',
+ component: WithId,
},
{
path: '/named-one',
],
})
+router.beforeEach(async (to, from) => {
+ if (to.name === 'id') {
+ const toId = Number(to.params.id)
+ const fromId = Number(from.params.id)
+ // only do it when we are going backwards
+ if (!Number.isNaN(toId) && !Number.isNaN(fromId) && toId < fromId) {
+ await new Promise(r => setTimeout(r, 250))
+ }
+ }
+})
+
// preserve existing query
const originalPush = router.push
router.push = to => {
<li><router-link id="update-query" :to="{ query: { n: (Number($route.query.n) || 0) + 1 }}" v-slot="{ route }">{{ route.fullPath }}</router-link></li>
<li><router-link to="/named-one">/named-one</router-link></li>
<li><router-link to="/named-two">/named-two</router-link></li>
+ <li><router-link to="/b/1">/b/1</router-link></li>
+ <li><router-link to="/b/2">/b/2</router-link></li>
+ <li><router-link to="/b/3">/b/3</router-link></li>
</ul>
<template v-if="testCase === 'keepalive'">
)
}
+const baseURL = 'http://localhost:3000/guards-instances'
+
module.exports = {
'@tags': [],
browser.end()
},
+ /** @type {import('nightwatch').NightwatchTest} */
+ 'cancel pending pop navigations': function (browser) {
+ browser
+ .url(baseURL + '/')
+ .waitForElementPresent('#app > *', 1000)
+
+ .click('#test-normal')
+ .click('li:nth-child(11) a')
+ .click('li:nth-child(12) a')
+ .click('li:nth-child(13) a')
+ .back()
+ .back()
+ .waitForElementPresent('#app > #with-id-1', 1000)
+ .assert.urlEquals(baseURL + '/b/1?testCase=')
+
+ .end()
+ },
+
/** @type {import('nightwatch').NightwatchTest} */
'guards instances transition': function (browser) {
browser
return Promise.reject()
}
// do not restore history on unknown direction
- if (info.delta) routerHistory.go(-info.delta, false)
+ if (info.delta) {
+ routerHistory.go(-info.delta, false)
+ }
// unrecognized error, transfer to the global handler
return triggerError(error, toLocation, from)
})
// revert the navigation
if (failure) {
- if (info.delta) {
+ if (
+ info.delta &&
+ // a new navigation has been triggered, so we do not want to revert, that will change the current history
+ // entry while a different route is displayed
+ !isNavigationFailure(failure, ErrorTypes.NAVIGATION_CANCELLED)
+ ) {
routerHistory.go(-info.delta, false)
} else if (
info.type === NavigationType.pop &&