Is there a way to escape the SPA routing?
Closed this issue · 5 comments
I have mutliple associated applications running on a parent domain, that will sometimes need to link to each other.
Let's say the thing lives at example.com. The Svelte app using svelte-router
is on /projects
, where it handles its content through nested routes – /projects/my-example-project
for instance.
When I now create a Navigate
or anchor element linking to /otherapp
or example.com/otherapp
, the SPA router can't find a configured route and shows a 404 page – instead of requesting the page from the server. While this is in itself expected behaviour, apart from setting target="_blank"
I don't see a way to reliably handle this scenario.
I know there's a way to display a custom 404 page – is there a way to handle requests that would result in a 404 before routing happens and send failed root-relative URLs or URLs for the same base domain back up to the server? Anything else I've missed?
Thanks in advance.
I think that problem would be easily solved having a global prefix. That way the router will only try to resolve routes that matches the prefix. /projects
in your case.
It should not be difficult to change.
I'll add it to my ToDo list.
I've created version 5.8.0
that include a prefix configuration option that should solve your problem.
https://github.com/jorgegorka/svelte-router#route-prefix
Please test it and let me know how it goes.
Best,
Great, thanks! I'll take a look and post my feedback. 🙂
Sorry for the late reply, I only just got around to testing it – and it works beautifully, just as I expected.
Thank you for this magnificent tool and your lightning-fast reaction to my problem, appreciate the great work!
@AndreasMaros Thank you for your comment!