question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Handling /index paths

See original GitHub issue

I 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:closed
  • Created 10 months ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jakobrosenbergcommented, Nov 20, 2022

You could do ./something.svelte instead 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/index so I think keeping the solution in the presentation layer (replaceState) makes it easier to reason about the internals.

1reaction
jakobrosenbergcommented, Nov 17, 2022

My mistake. I had misread your original post.

/path and /path/index are the same paths, so you wouldn’t be redirecting. At least not internally.

I think urlTransform might be what you’re looking for. https://www.routify.dev/docs/config/runtime

If that doesn’t work, you can also use history.replaceStateNative combined with $afterPageLoad.

// in your root _layout.svelte
import { afterPageLoad }  from '@roxi/routify'

$afterPageLoad(page => {
  const newUrl = location.href.replace(/\/index$/, '')
  history.replaceStateNative(null, null, newUrl)
}) 
Read more comments on GitHub >

github_iconTop Results From Across the Web

indexPathForSelectedRow | Apple Developer Documentation
An index path that identifies the row and section of the selected row. ... The value of this property is an index path...
Read more >
Index paths | HCL Digital Experience - HCL Product Documentation
Index paths are used to refer to components in the component hierarchy. They are based on the index or position of a component...
Read more >
Spring catch all route for index.html - Stack Overflow
I'm developing a spring backend for a react-based single page application where I'm using react-router for client-side routing. Beside the index. html page...
Read more >
8 Optimizer Access Paths - Oracle Help Center
An access path is a technique used by a query to retrieve rows from a row source. ... Bitmap Index Access Paths ·...
Read more >
TS Paths not working with index.ts when using a wildcard ...
Hi, I am using paths to point to another project ( I am using lerna), anyway, I have the following path setup. "paths":...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found