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

Combination of index route and dynamic route doesn't seem to get resolved properly #23

Closed
bux opened this issue Mar 15, 2021 · 8 comments

Comments

@bux
Copy link

bux commented Mar 15, 2021

image

With the above setup of pages, when calling localhost:3000/menuplan/ it seems that the dynamic route is being used instead of the index route.

Am I doing something wrong here?

Version: 0.7.0

@hannoeru
Copy link
Owner

hannoeru commented Mar 15, 2021

It works, can you provide more context?
or try to upgrade vue-router to latest version.

@bux
Copy link
Author

bux commented Mar 15, 2021

A simple repro would be:

  • Clone vitesse by antfu (or create a new github project by using this template)
  • Create a new vue file below ~/src/pages/hi and call it index.vue
  • Add a <template/> with some demo content
  • Run npm run dev
  • Try to open: http://localhost:3333/hi/

Observe how the dynamic route is being used instead of the newly created index route

@hannoeru
Copy link
Owner

hannoeru commented Mar 16, 2021

That is vite-plugin-vue-layouts's bug, the work around for now is:

// add to main.ts
routes[0].children.forEach((i: any) => {
  i.path = i.path.substring(1)
  if (i.path.endsWith('?'))
    i.path = i.path.slice(0, -1)
})

P.S. That didn't handle deep routes
Cc @JohnCampionJr

@bux
Copy link
Author

bux commented Mar 16, 2021

Thank you. This has worked. Do you want me to open an issue on vite-plugin-vue-layouts's repo?

@hannoeru
Copy link
Owner

Ok, then I will close this one.

@shroudedcode
Copy link

shroudedcode commented Mar 26, 2021

I'm also running into this issue and I'm not using vite-plugin-vue-layouts.

My pages directory looks like this:

├── [...notfound].vue
├── things
│   ├── [thing].vue
│   └── index.vue
└── index.vue

And these are my generated routes:

[
  { "name": "notfound", "path": "/:notfound(.*)" },
  { "name": "index", "path": "/" },
  // This route is always being matched:
  { "name": "things-thing", "path": "/things/:thing?" },
  { "name": "things", "path": "/things" }
]

Edit: Manually removing the ? at the end of the path (which is sort of what you suggested here) fixes the issue, but I don't see why it should have been added there in the first place. Under what circumstances would someone want their route's parameter to be optional and are those circumstances common enough to be the default behavior? 🤔

@hannoeru
Copy link
Owner

Optional parameters is removed from v0.9.0

@shroudedcode
Copy link

The new version fixed it. Thanks a lot for this great package, @hannoeru! 💚

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

3 participants