T
TanStack2y ago
foreign-sapphire

make trailing slashes configurable

I can see that right now, TanStack router always removes trailing slashes. This might be fine for most cases, but for instance, we serve an SPA from a django server, which is customized to always have trailing slashes. So if I load the browser on /foo/, the server will serve the correct SPA, but then TanStack router takes away the trailing slash, leaving /foo. If the user then re-loads the page, we're seeing a server-side redirect from django again towards /foo/, and then the router takes the slash away again. Could we get an option like nextJs has it: trailingSlash: 'alyways' | 'never' | 'preserve' , defaulting to never for backwards compatibility? Or is there a deeper reasoning why the router removes trailing slashes?
14 Replies
provincial-silver
provincial-silver2y ago
💯
vicious-gold
vicious-gold2y ago
sounds like a good idea
foreign-sapphire
foreign-sapphireOP2y ago
I can contribute this if you can point me to the direction where we now strip the trailing slashes in the code ...
absent-sapphire
absent-sapphire2y ago
Not sure if this is exactly it, but Tanner very recently pushed this commit regarding removing trailing slashes. https://github.com/TanStack/router/commit/b849a8ad87ecfe2fa3c7424f6d2398b766d506de
provincial-silver
provincial-silver2y ago
That commit was only for relative path resolution. Yes, we may need to consider any future options of keeping, or removing trailing slashes in this function that I modified, but this was merely to add some consistency to the way that we interpret relative paths.
foreign-sapphire
foreign-sapphireOP2y ago
hm, this seems a bit above my paygrade 😅 . I tried to change location parsing here (https://github.com/TanStack/router/blob/0ce37dca928042c37562242adc7d565cf4888e77/packages/react-router/src/router.ts#L551), but it didn't really make a difference 🤔
GitHub
router/packages/react-router/src/router.ts at 0ce37dca928042c375622...
🤖 Fully typesafe Router for React (and friends) w/ built-in caching, 1st class search-param APIs, client-side cache integration and isomorphic rendering. - TanStack/router
vicious-gold
vicious-gold2y ago
if I remove trimRight and open up /posts/ in the basic-file-based example, the trailing slash is kept otherwise, it is removed
vicious-gold
vicious-gold2y ago
@Tanner Linsley can you please review?
provincial-silver
provincial-silver2y ago
Approved
vicious-gold
vicious-gold2y ago
released in v1.27.0
foreign-sapphire
foreign-sapphireOP2y ago
I can confirm trailingSlash: 'always' is working great 🚀 . Thank you so much @Manuel Schiller 🙏
provincial-silver
provincial-silver2y ago
Yeah this is great!

Did you find this page helpful?