vite-plugin-pages
vite-plugin-pages copied to clipboard
catch all route not catch index route
Describe the bug
Case 1
I have a project, pages dir looks like this:
./src/pages
├── [...all].tsx
└── blog
└── [...all].tsx
└── [id].tsx
When enter /blog/1
it display blog/[id].tsx
, it's correct. But, when I enter /blog
, it looks not fallback to catch all route(blog/[...all].tsx
). Currently, it display nothing.
Case 2
./src/pages
├── [...all].tsx
└── blog
└── [id].tsx
When I enter /blog
, it looks not fallback to catch all route([...all].tsx
). Currently, it display nothing.
Maybe it's related to resolved routes data, when routes data looks like this will meet above issue.
{
path: 'blog'
children: [
{
path: '*'
}
]
}
The solution flat children routes(if parent route not found)
// if `blog.tsx` not exist
{
path: 'blog/*',
element: blog/[...all].tsx
}
// if `blog.tsx` exist
{
path: 'blog',
element: blog.tsx
children: [
{
path: '*',
element: [...all].tsx
},
{
index: true,
path: '',
element: index.tsx
}
]
}
Reproduction
https://github.com/JiangWeixian/vite-plugin-pages-minirepo
System Info
System:
OS: macOS 12.5.1
CPU: (10) x64 Apple M1 Max
Memory: 164.31 MB / 64.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 14.20.1 - ~/.nvm/versions/node/v14.20.1/bin/node
Yarn: 1.22.19 - ~/.nvm/versions/node/v14.20.1/bin/yarn
npm: 6.14.17 - ~/.nvm/versions/node/v14.20.1/bin/npm
Browsers:
Chrome: 112.0.5615.49
Firefox: 111.0.1
Safari: 15.6.1
Used Package Manager
pnpm
Validations
- [X] Follow the Code of Conduct
- [X] Read the docs.
- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- [X] Check that this is a concrete bug. For Q&A please open a GitHub Discussion.
- [X] The provided reproduction is a minimal reproducible example of the bug.
Closed, I think it related to react-router.
https://github.com/remix-run/react-router/issues/10357