template: `<div>home</div>`,
}
-const Foo: RouteComponent = { template: '<div>foo</div>' }
-const Bar: RouteComponent = { template: '<div>bar</div>' }
+const Foo: RouteComponent = { template: '<div>Foo</div>' }
+const Bar: RouteComponent = { template: '<div>Bar</div>' }
const Unicode: RouteComponent = {
setup() {
router)</a
>
</li>
+ <li><a href="#/foo">/foo (regular hash)</a></li>
</ul>
<p>
hash: <code id="hash">{{ route.hash }}</code>
</p>
- <router-view></router-view>
+ <router-view class="view"></router-view>
</div>
`,
})
)
.click('li:nth-child(3) a')
.assert.urlEquals(baseURL + '/bar')
+ .assert.containsText('.view', 'Bar')
.click('li:nth-child(2) a')
.assert.urlEquals(baseURL + '/foo')
.click('li:nth-child(4) a')
.click('li:nth-child(5) a')
.assert.containsText('#param', 'é')
+ // regular links should not break navigation
+ .click('li:nth-child(10) a')
+ .assert.urlEquals(baseURL + '/foo')
+ .assert.containsText('#path', '/foo')
+ .assert.containsText('.view', 'Foo')
+
.end()
},
state: StateEntry | null
}) => {
const to = createCurrentLocation(base, window.location)
-
- if (!state) return replace(to.fullPath)
-
const from: HistoryLocationNormalized = location.value
const fromState: StateEntry = historyState.value
- location.value = to
- historyState.value = state
+ let delta = 0
+
+ if (state) {
+ location.value = to
+ historyState.value = state
- // ignore the popstate and reset the pauseState
- if (pauseState && pauseState.fullPath === from.fullPath) {
- pauseState = null
- return
+ // ignore the popstate and reset the pauseState
+ if (pauseState && pauseState.fullPath === from.fullPath) {
+ pauseState = null
+ return
+ }
+ delta = fromState ? state.position - fromState.position : 0
+ } else {
+ replace(to.fullPath)
}
- const delta = fromState ? state.position - fromState.position : 0
// console.log({ deltaFromCurrent })
// Here we could also revert the navigation by calling history.go(-delta)
// this listener will have to be adapted to not trigger again and to wait for the url
if (
isNavigationFailure(error, ErrorTypes.NAVIGATION_GUARD_REDIRECT)
) {
- routerHistory.go(-info.delta, false)
+ // do not restore history on unknown direction
+ if (info.delta) routerHistory.go(-info.delta, false)
// the error is already handled by router.push we just want to avoid
// logging the error
pushWithRedirect(
// avoid the then branch
return Promise.reject()
}
- // TODO: test on different browsers ensure consistent behavior
- routerHistory.go(-info.delta, false)
+ // do not restore history on unknown direction
+ if (info.delta) routerHistory.go(-info.delta, false)
// unrecognized error, transfer to the global handler
return triggerError(error)
})
)
// revert the navigation
- if (failure) routerHistory.go(-info.delta, false)
+ if (failure && info.delta) routerHistory.go(-info.delta, false)
triggerAfterEach(
toLocation as RouteLocationNormalizedLoaded,