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

Don't change anchor links to use the history API if the router doesn't have a match #18

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

jbuckner
Copy link

@jbuckner jbuckner commented Jan 16, 2021

The use case for this is integrating router-slot into a server-side routed web app where we're proxy-passing from the same parent URL. ie: foo.com/about and foo.com/products where /about is using router-slot, but /products is not. Anchor links to /products will currently try to be handled by router-slot because it's a relative link, even if you don't have a route for it.

With this change, if you don't have a catch-all route in router-slot, it will allow the browser to redirect the link to the server-side routed /products URL.

If the app has a catch-all route, it will still be handled client-side.

Allow links to be handled by the browser if the router does not support the route.

In the case where you may be proxy-passing from a server-side routing web app to a client-side routing web app, many of the URLs may be unsupported client-side. This allows the links to pass through to the parent router.
@jbuckner jbuckner changed the title Allow browser to handle anchor tags with no route Don't change anchor links to use the history API if the router doesn't have a match Jan 17, 2021
@jbuckner
Copy link
Author

Hmm I didn't account for when there are multiple router-slots on screen. With this PR, it would put multiple click listeners on the window and only respond to the router that attached it. I think this can be solved by only attaching it to the top-level router. Testing this idea.

Previously if there were multiple router-slots on-screen, each one would have its own AnchorHandler responding to itself. We only want one at the root.
@jbuckner
Copy link
Author

That was an easy fix. Now I'm only binding the anchor handler in the root router so we only get one click handler and since it's being used to determine whether the route should be handled or not, the root router should be the last in line to make that determination if the route can be handled.

@christophe-g
Copy link

@jbuckner - great, many thanks for this.

Actually, I favored this router mostly because of the way it manages nested router-slot. As I have some parts of the application that can appear under different root path, I'd need ways to write relative ROUTES (without any ref to a route prefix).

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

Successfully merging this pull request may close these issues.

2 participants