0

I am trying to make these routes:

{
  path: '/',
  name: 'home',
  component: Home
},
{
  path: '/:username',
  name: 'login',
  component: Login
},
{
  path: '/dashboard',
  name: 'dashboard',
  component: Dashboard
}

But when I try to open /dashboard, I get Login page.

2 Answers 2

1

The order is important here. You can swap /dashboard and /:username position

[{
  path: '/',
  name: 'home',
  component: Home
},
{
  path: '/dashboard',
    name: 'dashboard',
      component: Dashboard
},
{
  path: '/:username',
  name: 'login',
  component: Login
}]
Sign up to request clarification or add additional context in comments.

2 Comments

Oh wow. This is just works, thank you! Is this described in docs?
@ittus Maybe you can hep me. Look at this : stackoverflow.com/questions/57836601/…
1

That's normal. Router is matching the routes from first to last. /dashboard totally matches /:username with username == 'dashboard'

You should place the login roote at the end of the array, but even better you'd prefix it to be safer (like /user/:username)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.