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

overlapping in defining routes in nuxtjs router #70

Closed
kazem2020 opened this issue Mar 12, 2020 · 1 comment
Closed

overlapping in defining routes in nuxtjs router #70

kazem2020 opened this issue Mar 12, 2020 · 1 comment

Comments

@kazem2020
Copy link

kazem2020 commented Mar 12, 2020

Version 1.5.0

I'm trying to develop a blog with nuxtjs. But I have problem with routing.
I define this route localhost/@:username/:slug to show a post. also I want to have these routes:
localhost/@:username/edit, localhost/@:username/posts, localhost/@:username/followers, ...

But it makes disturbance, and all of them route to show post page.

my router:


import Vue from 'vue';
import Router from 'vue-router';
import {scrollBehavior} from '~/utils';

Vue.use(Router);

const page = path => () => import(`~/pages/${path}`).then(m => m.default || m);

const routes = [
    {
    path: '/@:username',
    component: page('user/profile/index.vue'),
    children: [
        {path: '', name: 'profile', component: page('user/profile/profile.vue'),},
        {path: 'edit', name: 'profile-edit', component: page('user/profile/edit.vue')},
        {path: 'following', name: 'profile-following', component: page('user/profile/following.vue')},
        {path: 'followers', name: 'profile-followers', component: page('user/profile/followers.vue')},
     ]
    },
    {path: '/@:username/:slug', name: 'post', component: page('site/posts/show-post.vue')},
];

export function createRouter() {
    return new Router({
        routes,
        scrollBehavior,
        mode: 'history'
    });
}

@zabavnikov
Copy link

Hello! I'm not quite sure about this, but any route in the child section matches the mask @:username/:slug and since it is the last in the list, show-post.vue is displayed on this.

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