hannoeru / vite-plugin-pages

File system based route generator for ⚡️Vite
MIT License
1.84k stars 127 forks source link

catch all route not catch index route #402

Open JiangWeixian opened 1 year ago

JiangWeixian commented 1 year ago

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

JiangWeixian commented 1 year ago

Closed, I think it related to react-router.

https://github.com/remix-run/react-router/issues/10357