Handling /index paths
See original GitHub issueI am new to Routify (and I am liking it a lot so far!), but there is one thing I am trying to do that I have not been able to find information about online: customize the way /index paths are handled. Specifically, what I am after is a way to redirect all /index paths to the corresponding /. For example, if this is my file structure:
/pages
/something
index.svelte
index.svelte
I would have
//index/something/something/index
available at runtime. However, I would like to implement redirects (ideally using something like $redirect so the browser history is not polluted) from /index to / and /something/index to /something respectively. Is there a pattern for this? Or, is it not possible using the current Routify API? I know this use case can be handled at the server level, but I was hoping there might be a way to do it directly in the application code instead.
For reference, I am using v2.18.8 of @roxi/routify. I apologize in advance if this is a common/simple use case to solve and my internet search skills have failed me.
Issue Analytics
- State:
- Created 10 months ago
- Comments:8 (4 by maintainers)

Top Related StackOverflow Question
You could do
./something.svelteinstead of./something/index.svelte, but I would advice against it. I find mixing library routing and file routing confusing.Technically you are navigating to
something/indexso I think keeping the solution in the presentation layer (replaceState) makes it easier to reason about the internals.My mistake. I had misread your original post.
/pathand/path/indexare the same paths, so you wouldn’t be redirecting. At least not internally.I think
urlTransformmight be what you’re looking for. https://www.routify.dev/docs/config/runtimeIf that doesn’t work, you can also use
history.replaceStateNativecombined with$afterPageLoad.