]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
fix: add mixin only on client
authorEduardo San Martin Morote <posva13@gmail.com>
Wed, 5 Feb 2020 13:19:08 +0000 (14:19 +0100)
committerEduardo San Martin Morote <posva13@gmail.com>
Wed, 5 Feb 2020 13:19:08 +0000 (14:19 +0100)
src/router.ts

index 62a93a3233a2183bd0d3af1aba78eb01cc143cca..e5f0cb8e12246bbbd2309b436fcf06160cee74bd 100644 (file)
@@ -479,18 +479,19 @@ function applyRouterPlugin(app: App, router: Router) {
 
   let started = false
   // TODO: can we use something that isn't a mixin?
-  app.mixin({
-    beforeCreate() {
-      if (!started) {
-        // TODO: this initial navigation is only necessary on client, on server it doesn't make sense
-        // because it will create an extra unecessary navigation and could lead to problems
-        router.push(router.history.location.fullPath).catch(err => {
-          console.error('Unhandled error', err)
-        })
-        started = true
-      }
-    },
-  })
+  // TODO: this initial navigation is only necessary on client, on server it doesn't make sense
+  // because it will create an extra unecessary navigation and could lead to problems
+  if (isClient)
+    app.mixin({
+      beforeCreate() {
+        if (!started) {
+          router.push(router.history.location.fullPath).catch(err => {
+            console.error('Unhandled error', err)
+          })
+          started = true
+        }
+      },
+    })
 
   // TODO: merge strats?
   app.provide('router', router)