Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use dynamic routing prompts Uncaught Error: [vue-router] "path" is required in a route configuration #3856

Closed
cMing1997 opened this issue Aug 4, 2023 · 1 comment

Comments

@cMing1997
Copy link

cMing1997 commented Aug 4, 2023

Version

3.6.5

Reproduction link

codesandbox.io

Steps to reproduce

  1. Encapsulates a CommonRouter that handles common things about routing, exporting routes after use
import Vue from 'vue';
import Router from 'vue-router';
Vue.use(Router);


const router: any = new Router({
    scrollBehavior() {
        return {
            x: 0,
            y: 0
        }
    }
});


router.authCode = '';


router.beforeEach((to, from, next) => {
      next();
});

export default router;
  1. The single-page routing file references the CommonRouter, uses addRoutes to add dynamic routing, and prompts the page :
    vue-router.esm.js:16 [vue-router] router.addRoutes() is deprecated and has been removed in Vue Router 4. Use router.addRoute() instead.
import router from 'lib/CommonRouter';
const LayoutView = () => import("@/components/LayoutView/index.vue");
const WelcomeIndex= () => import("@/pages/welcome/views/home/index.vue");

router.addRoutes([{
    path: '/',
    component: LayoutView,
    children: [{
        path: 'index',
        name: 'welcomeIndex',
        component: WelcomeIndex
    }]
}],);
export default router
  1. So use addRoute, the page directly error, prompt : Uncaught Error: [vue-router] "path" is required in a route configuration

What is expected?

addRoutes and addRoute One of them is available and error-free

What is actually happening?

There is a warning prompt when using addRoutes, and an error is reported directly when using addRoute

@posva
Copy link
Member

posva commented Aug 5, 2023

router.addRoutes([
  {
    path: "/",
    component: LayoutView,
    children: [
      {
        path: "home",
        name: "home",
        component: Home
      }
    ]
  }
]);

or without the array.


Please, next time consider using the Discord server, Discussions (if enabled in this repository), or StackOverflow for questions first. But feel free to come back and open an issue if it turns out to be a bug 🙂

@posva posva closed this as not planned Won't fix, can't repro, duplicate, stale Aug 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants