From 35c6ac411dd6d1d218c56c0d764df2e5f804f975 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Mon, 14 Jun 2021 14:54:36 +0100 Subject: [PATCH] fix(vue-app): check whether route exists within nuxt app before replacing (#9431) [release] --- packages/vue-app/template/index.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/vue-app/template/index.js b/packages/vue-app/template/index.js index 00a20345f8..5fdf128b91 100644 --- a/packages/vue-app/template/index.js +++ b/packages/vue-app/template/index.js @@ -270,7 +270,12 @@ async function createApp(ssrContext, config = {}) { // Wait for async component to be resolved first await new Promise((resolve, reject) => { - router.replace(app.context.route.fullPath, resolve, (err) => { + const { route } = router.resolve(app.context.route.fullPath) + // Ignore 404s rather than blindly replacing URL + if (!route.matched.length && process.client) { + return resolve() + } + router.replace(route, resolve, (err) => { // https://github.com/vuejs/vue-router/blob/v3.4.3/src/util/errors.js if (!err._isRouter) return reject(err) if (err.type !== 2 /* NavigationFailureType.redirected */) return resolve()