Search code examples
vuejs3migrationvue-router

Getting blank page after migrating to Vue-Router v4


I took over this vue project and want to migrate it to Vue 3. I followed the steps in this guide https://v3-migration.vuejs.org/migration-build.html and was now on the step to migrate vue-router from v3 to v4. After implementing the necessary changes according to https://router.vuejs.org/guide/migration/ I am getting a blank page. It was working before this migration, the only changes I've made were to main.js and router/index.js. But I can't 100% rule out the error lying elsewhere.

I am getting no errors in console except a deprecation WATCH_ARRAY warning from the compat on the router. But as far as I can see, that is expected behaviour https://github.com/vuejs/router/issues/1315 I have tried many different solutions from others having a similar issue, but nothing worked so far.

dependencies

"dependencies": {
    "babel-polyfill": "^6.26.0",
    "@vue/compat": "^3.2.6",
    "axios": "^1.5.0",
    "currency-formatter": "^1.5.5",
    "fuse.js": "^6.6.2",
    "isomorphic-fetch": "^3.0.0",
    "localforage": "^1.10.0",
    "lodash-es": "^4.17.21",
    "moment": "^2.29.4",
    "qs": "^6.11.2",
    "vue": "^3.2.6",
    "vue-router": "^4.2.4",
    "vuex": "^4.1.0",
    "window-or-global": "^1.0.1"
  },
  "devDependencies": {
    "acorn": "^8.10.0",
    "@babel/core": "^7.22.10",
    "@babel/eslint-parser": "^7.22.10",
    "@babel/runtime": "7.22.10",
    "@babel/runtime-corejs2": "7.22.10",
    "@babel/plugin-proposal-class-properties": "^7.0.0",
    "@babel/plugin-proposal-decorators": "^7.0.0",
    "@babel/plugin-proposal-export-namespace-from": "^7.0.0",
    "@babel/plugin-proposal-function-sent": "^7.0.0",
    "@babel/plugin-proposal-json-strings": "^7.0.0",
    "@babel/plugin-proposal-numeric-separator": "^7.0.0",
    "@babel/plugin-proposal-throw-expressions": "^7.0.0",
    "@babel/plugin-syntax-dynamic-import": "^7.0.0",
    "@babel/plugin-syntax-import-meta": "^7.0.0",
    "babel-plugin-syntax-jsx": "^6.18.0",
    "@babel/plugin-transform-runtime": "^7.0.0",
    "@babel/preset-env": "^7.0.0",
    "@openapitools/openapi-generator-cli": "2.7.0",
    "@vue/compiler-sfc": "^3.2.6",
    "autoprefixer": "^7.1.2",
    "babel-loader": "^8.3.0",
    "babel-plugin-istanbul": "^4.1.1",
    "babel-plugin-transform-vue-jsx": "^3.5.0",
    "chai": "^4.3.8",
    "chalk": "^5.3.0",
    "copy-webpack-plugin": "^5.1.2",
    "cross-env": "^7.0.3",
    "css-loader": "^3.6.0",
    "eslint": "^8.47.0",
    "eslint-config-standard": "^17.1.0",
    "eslint-friendly-formatter": "^4.0.1",
    "eslint-plugin-import": "^2.28.0",
    "eslint-plugin-n": "16.0.1",
    "eslint-plugin-node": "^11.1.0",
    "eslint-plugin-promise": "^6.1.1",
    "eslint-plugin-standard": "^3.0.1",
    "eslint-plugin-vue": "^9.17.0",
    "eslint-webpack-plugin": "^2.2.1",
    "extract-text-webpack-plugin": "^3.0.0",
    "file-loader": "^1.1.4",
    "friendly-errors-webpack-plugin": "^1.7.0",
    "html-webpack-plugin": "^4.5.2",
    "inject-loader": "^4.0.1",
    "karma": "^6.4.2",
    "karma-coverage": "^2.2.1",
    "karma-mocha": "^2.0.1",
    "karma-phantomjs-launcher": "^1.0.2",
    "karma-phantomjs-shim": "^1.4.0",
    "karma-sinon-chai": "^2.0.2",
    "karma-sourcemap-loader": "^0.4.0",
    "karma-spec-reporter": "0.0.36",
    "karma-webpack": "^4.0.2",
    "mocha": "^10.2.0",
    "node-notifier": "^10.0.1",
    "node-sass": "^4.13.1",
    "optimize-css-assets-webpack-plugin": "^3.2.1",
    "ora": "^5.4.1",
    "phantomjs-prebuilt": "^2.1.14",
    "portfinder": "^1.0.32",
    "postcss-import": "^11.0.0",
    "postcss-loader": "^2.0.8",
    "postcss-url": "^7.2.1",
    "rimraf": "^3.0.2",
    "sass-loader": "^7.3.1",
    "semver": "^7.5.4",
    "shelljs": "^0.8.5",
    "sinon": "^15.2.0",
    "sinon-chai": "^3.7.0",
    "uglifyjs-webpack-plugin": "^2.2.0",
    "url-loader": "^4.1.1",
    "vue-loader": "^16.8.3",
    "vue-style-loader": "^4.1.3",
    "webpack": "^4.46.0",
    "webpack-bundle-analyzer": "^2.9.0",
    "webpack-cli": "4.10.0",
    "webpack-dev-server": "^4.15.1",
    "webpack-merge": "^4.2.2"
  },

main.js

import 'babel-polyfill'

import { createApp } from 'vue'
import { router } from './router'

import root from 'window-or-global'
import AppWrapper from './components/AppWrapper.vue'
import { store } from './store'

import './assets/css/font-awesome.css'

const appWrapper = createApp(AppWrapper)

appWrapper.use(store)
appWrapper.use(router)

root.$router = router
root.$store = store

appWrapper.config.lang = 'de'

appWrapper.mount('#appWrapper')

router/index.js

import { createRouter, createWebHistory } from 'vue-router'
import InventoryPage from '../components/pages/InventoryPage'

export const router = createRouter({
  history: createWebHistory(process.env.BASEPATH),
  routes: [
    {
      path: '/',
      name: 'StartPage',
      redirect: {
        name: 'Inventory'
      }
    },
    {
      path: '/inventory',
      name: 'Inventory',
      component: InventoryPage
    },
    {
      path: '/:pathMatch(.*)*',
      redirect: '/'
    }
  ]
})

Solution

  • So, after setting up a smaller project and tinkering around with that, I have found the problem:

    For some reason the vue-router did not work with the vue compat mode. After removing compat from the project and letting it run directly on vue 3 everything was working as expected. It might have been that I did something wrong with configuring the compat mode though.