kobweb
kobweb copied to clipboard
Support trailing slash behavior customization
See also: https://nextjs.org/docs/pages/api-reference/next-config-js/trailingSlash
And see also: https://github.com/varabyte/kobweb/blob/f74a1b9b6302ddcce0477c126ed75096fb60fb18/frontend/kobweb-core/src/jsMain/kotlin/com/varabyte/kobweb/navigation/Router.kt#L376
Up until now, we've sidestepped this by being pretty loose with trailing slashes in Kobweb.
In other words, if a user registers "/example-route", then that route will be visited (of course) if typed in directly or if /example-route/ was typed in (at which point it would be redirected).
Some users want the reverse -- they want the trailing-slash version to be the canonical URL, so even if they define a @Page (or markdown file) at ExampleRoute.kt, it should generate /example-route/
The one tricky thing with Kobweb is we let users break their code up into separate modules (and libraries), but for consistency, this is probably something we only want to let the app decide on the final behavior, and not have to specify in every module.
So we'd probably need a way to take a route registered at "/a/b/c" and retroactively treat it as "/a/b/c/" (unless of course "/a/b/c/" was separately registered explicilty.
Any updates on this @bitspittle?
I'll be honest, it hasn't been on my radar and might not be for a while.
Note that you have access to registering a route interceptor: https://github.com/varabyte/kobweb/blob/33838f5bdfcbfda322c2a3df3c3c0901bc37f1ce/frontend/kobweb-core/src/jsMain/kotlin/com/varabyte/kobweb/navigation/Router.kt#L294
And also the client side navigation logic will try to add a slash if /example-route isn't found but /example-route/ is: https://github.com/varabyte/kobweb/blob/33838f5bdfcbfda322c2a3df3c3c0901bc37f1ce/frontend/kobweb-core/src/jsMain/kotlin/com/varabyte/kobweb/navigation/Router.kt#L377 and a fullstack Kobweb server will handle that case too. (A static hosting service would probably fail though without configuration)
@shubhamsinghshubham777 Can you share a specific use case would you like to support?
the client side navigation logic will try to add a slash if /example-route isn't found but /example-route/ is
@bitspittle My case is similar, but for query parameters. The router is able to find this path:
http://localhost:8080/results/?search_query=test
but not this:
http://localhost:8080/results?search_query=test
Let me know if this should be filed under its own issue.
Ah sure, let's file a new issue for that! Because we could fix it without adding a trailing slash config parameter. I will need to double check the code, but that probably should have worked and it's just an oversight with my logic.
Ah sure, let's file a new issue for that! Because we could fix it without adding a trailing slash config parameter. I will need to double check the code, but that probably should have worked and it's just an oversight with my logic.
No issues at all, I'll file another issue to keep things clean ✅