Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow preventing any action in case of route change. #204

Open
weeblr opened this issue Mar 2, 2021 · 2 comments
Open

Allow preventing any action in case of route change. #204

weeblr opened this issue Mar 2, 2021 · 2 comments

Comments

@weeblr
Copy link

weeblr commented Mar 2, 2021

This is a follow up to #188, which was a slightly different one. I'd like to be able to prevent any route action to happen in some cases and that cannot be solved currently with guards.

The use case is running a svelte app inside of another app or site. Typically in my case, a WordPress or Joomla extension or theme.

As the parent CMS have links that may use hashes as well, such as href='#', this causes svelte-spa-router (SSR) to either trigger a 404 for the app (if I set up a '*" catch-all route) or to clear the app as if no route matches, the component variable is set to null.

I namespaced my routes to avoid conflict with any other #xxx that may exist on the page from the CMS, but I cannot prevent SSR to react to clicks on CMS links, outside of my apps.

If I use a guard and return false when not one my routes, the router does not load any route at all, so I end up with a blank screen.

Either a guard could be made to return true, false or 'cancel' or null to do absolutely nothing instead of killing the component if no route is matched. Just keep the current one, do nothing.

Or the pre-condition should be made able to modify the route somehow.

Note that I also tried:

by using a route guard that fails on some condition. When the condition fails, the router triggers the conditionsFailed event and there you can change the URL

A workaround here would be to set the route back to the previous one, before the click on that external href, but the previous location information has been lost at this stage, the route has already been killed.

Thanks and regards

@NfNitLoop
Copy link

This would be handy for the use case I mentioned here: #196 (comment)

In particular, since the querystring is part of the route (though I'm not using it for my routes) any changes to the querystring cause the route to be rerendered. It would be nice to opt out of that so I could use the querystring to keep some page state in the URL.

@michapixel
Copy link

i'm having the exact same issue as the OP is describing. I'd also like to have simple 'external' links (maybe rel="external" can be excluded somehow from catching every link in the DOM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants