sapper
sapper copied to clipboard
src/routes/index/index.svelte
Description
According to documentation:
src/routes/about/index.svelteis treated the same assrc/routes/about.svelte
It is reasonable to assume that src/routes/index/index.svelte would be treated the same as src/routes/index.svelte. So I created the following structure:
routes
├── about
| ├── index.svelte
| └── components
├── contact
| ├── index.svelte
| └── components
├── index
| ├── index.svelte
| └── components
├── _error.svelte
└── _layout.svelte
which results in a 404 on index. As a workaround I simply added an empty index.svelte file inside /routes, and that fixed everything:
routes
├── about
| ├── index.svelte
| └── components
├── contact
| ├── index.svelte
| └── components
├── index
| ├── index.svelte
| └── components
├── _error.svelte
├── _layout.svelte
└── index.svelte
For some reason it doesn't load the empty routes/index.svelte, but it loads the routes/index/index.svelte which seems counter-intuitive.
Logs
(index):1 Failed to load resource: the server responded with a status of 404 (Not Found)
Expected behavior
Treat src/routes/index/index.svelte same as src/routes/index.svelte.
Version info:
- Sapper 0.27.0
- Svelte 3.0.0
- Rollup
Another use case: Dynamically creating routes with a headless CMS. In my case, a page with the slug index is treated like index/index.svelte and the index route becomes unavailable.
The fact that an empty index.svelte file fixes the whole thing makes that not a proposal, but a bug that needs to be fixed. In my humble opinion.
Unfortunately, I am not smart enough to make a PR.
Edit: Well, my empty index.svelte is entirely ignored resulting in a 404 error as always. Is there a workaround for dynamic pages created using a [slug].svelte file?
I encountered the same problem now. I have a page titled “Index” and it should be accessible via an /index route. So I created a routes/index/ directory containing an index.svelte file—works. But now routes/index.svelte became unavailable.
Has anybody found a workaround? I would really like to refrain from renaming the route. The page has the title “Index” and should be reachable with that URL.
New project, same problem. The solution for the last project was a language identifier at the base of each route (e. g. en/index), which needed to be added anyways and made it eventually work.
This got me thinking:
routes
├── [route(index)]
| └── index.svelte
├── _error.svelte
├── _layout.svelte
└── index.svelte
Using a route with a dynamic parameter that only matches index (using a regular expression) seems to work as expected.