<input type="checkbox" v-model="shared.cancel" /> Cancel Next Navigation
</label>
<ul>
+ <li>
+ <router-link to="/n/%E2%82%AC">/n/%E2%82%AC</router-link>
+ </li>
+ <li>
+ <router-link to="/n/€">/n/€</router-link>
+ </li>
+ <li>
+ <a href="/n/%E2%82%AC">/n/%E2%82%AC (force reload)</a>
+ </li>
+ <li>
+ <a href="/n/€">/n/€ (force reload): not valid tho</a>
+ </li>
<li>
<router-link to="/">/</router-link>
</li>
{ path: '/', component: Home },
{ path: '/users/:id', name: 'user', component: User },
{ path: '/documents/:id', name: 'docs', component: User },
+ { path: '/n/€', name: 'euro', component },
{ path: '/n/:n', name: 'increment', component },
{ path: '/multiple/:a/:b', name: 'multiple', component },
{ path: '/long-:n', name: 'long', component: LongView },
current: HistoryLocationNormalized
forward: HistoryLocationNormalized | null
replaced: boolean
- scroll: ScrollToPosition
+ scroll: ScrollToPosition | null
}
// TODO: pretty useless right now except for typing
back: HistoryLocationNormalized | null,
current: HistoryLocationNormalized,
forward: HistoryLocationNormalized | null,
- replaced: boolean = false
+ replaced: boolean = false,
+ computeScroll: boolean = false
): StateEntry {
return {
back,
current,
forward,
replaced,
- scroll: computeScrollPosition(),
+ scroll: computeScroll ? computeScrollPosition() : null,
}
}
this.history.state.back,
this.history.state.current,
normalized,
- this.history.state.replaced
+ this.history.state.replaced,
+ // TODO: this is just not enough to only save the scroll position when not pushing or replacing
+ true
),
'',
this.location.fullPath,
(
to: RouteLocationNormalized,
from: RouteLocationNormalized,
- savedPosition: ScrollToPosition
+ savedPosition: ScrollToPosition | null
): ScrollPosition | Promise<ScrollPosition>
}
...matchedRoute,
}
this.updateReactiveRoute()
- this.handleScroll(toLocation, this.currentRoute).catch(err =>
- this.triggerError(err, false)
+ // TODO: refactor with a state getter
+ // const { scroll } = this.history.state
+ const { state } = window.history
+ this.handleScroll(toLocation, this.currentRoute, state.scroll).catch(
+ err => this.triggerError(err, false)
)
} catch (error) {
if (NavigationGuardRedirect.is(error)) {
private async handleScroll(
to: RouteLocationNormalized,
- from: RouteLocationNormalized
+ from: RouteLocationNormalized,
+ scrollPosition?: ScrollToPosition
) {
if (!this.scrollBehavior) return
- // TODO: handle other histories
- const { state } = window.history
- if (!state) return
- const scroll: ScrollToPosition | void = state.scroll
- if (!scroll) return
await this.app.$nextTick()
- const position = await this.scrollBehavior(to, from, scroll)
+ const position = await this.scrollBehavior(to, from, scrollPosition || null)
console.log('scrolling to', position)
scrollToPosition(position)
}