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

Route parameters matching incorrectly and redirecting to root? #88

Closed
nickyhajal opened this issue Nov 3, 2020 · 2 comments
Closed
Labels
question Further information is requested

Comments

@nickyhajal
Copy link

Here's a REPL that doesn't seem to be working on the website, but illustrates the situation if you run locally.

https://svelte.dev/repl/13608c5e9280428f81c0b8dc9bc2b97c?version=3.29.4

If you go to /a, it correctly outputs 2

If you go to /a/b, I would expect it to output 3 but it outputs 4 and redirects to /a

If you go to /a/b/c, it outputs 4 and redirects to /a/c

Why is this not behaving as expected? Am I doing something wrong?

@jorgegorka
Copy link
Owner

Hello @nickyhajal

Here is the right configuration :

const routes = [
    {
      name: '/',
      component: 'Comp1',
    },
    { 
      name: '/a/:id', component: 'Comp2', 
      nestedRoutes: [{ name: 'b', component: 'Comp4' }] 
    },
  ]

The reason behind it is that named params id in this example, are optional so /a/123 and /a are rendered by the same component Comp2 in the first case the param id will be 123 and in the second it'll be empty.

Then you can have nested routes but you need to use the nested route property to indicate it.

@jorgegorka jorgegorka added the question Further information is requested label Nov 4, 2020
@nickyhajal
Copy link
Author

Thanks for the quick response @jorgegorka, that makes sense!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants