mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 16:12:12 +00:00
refactor: unregister afterEach after route changed in guard
This commit is contained in:
parent
ceae5a8844
commit
7952de520c
@ -168,16 +168,13 @@ async function createApp (ssrContext) {
|
|||||||
if (process.server && ssrContext && ssrContext.url) {
|
if (process.server && ssrContext && ssrContext.url) {
|
||||||
await new Promise((resolve, reject) => {
|
await new Promise((resolve, reject) => {
|
||||||
router.push(ssrContext.url, resolve, () => {
|
router.push(ssrContext.url, resolve, () => {
|
||||||
let initSSR = true
|
|
||||||
// navigated to a different route in router guard
|
// navigated to a different route in router guard
|
||||||
router.afterEach(async (to, from, next) => {
|
const unregister = router.afterEach(async (to, from, next) => {
|
||||||
if (initSSR) {
|
ssrContext.url = to.fullPath
|
||||||
ssrContext.url = to.fullPath
|
app.context.route = await getRouteData(to)
|
||||||
app.context.route = await getRouteData(to)
|
app.context.params = to.params || {}
|
||||||
app.context.params = to.params || {}
|
app.context.query = to.query || {}
|
||||||
app.context.query = to.query || {}
|
unregister()
|
||||||
}
|
|
||||||
initSSR = false
|
|
||||||
resolve()
|
resolve()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user