Skip to content

In the scenario of dynamically adding a route using addRoute, no match found for location with path "/ xxx" appears before adding a route #1131

@jiankafei

Description

@jiankafei

What problem does this feature solve?

It is very common to add routes asynchronously and dynamically, such as dynamically adding accessible routes to the data returned through the interface. When accessing the page initially, because the route data is added to the route asynchronously, there is no route of the current path, so an error such as "no match found for location with path /xxx" will be reported.

During router 3.x, you can get asynchronous data and inject routing data, and then display the root router view to solve this problem. The specific methods are as follows.

<--launched The default is false. After data is loaded, it is set to true to load the view-->
<router-view v-if="launched"></router-view>

However, using router next, the above methods are no longer effective. Therefore, we hope to add a start method to the router instance. After all routing data is added to the route, start vue-router through the start method, so as to solve this problem perfectly.

What does the proposed API look like?

const router = createRouter({});
router.addRoute({
    path: '/aaa',
    name: 'aaa',
    component: () => import('@/views/Aaa.vue'),
});
// This method really starts the router
// Global can only be called once, and multiple calls are invalid
router.start();

Or implement the above functions in version 3. X.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions