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 absolute urls in transition calls #171

Open
ignatevdev opened this issue Jul 15, 2019 · 8 comments
Open

Allow absolute urls in transition calls #171

ignatevdev opened this issue Jul 15, 2019 · 8 comments

Comments

@ignatevdev
Copy link

Following the discussion in the PR 4Catalyzer/found-named-routes#57

It would be nice to allow absolute redirects inside the found's core.

A common use case would be redirecting the user to an external authentication provider, such as a SSO service.

In this case, we would need to determine that we have received an absolute URL and instead of modifying the history, make a window.location assignment.

Currently, this is not possible, since farce would try to make a push to a new route, which would not lead to a redirect in case of an absolute URL.

@ignatevdev
Copy link
Author

@taion If you could make a proposal for the correct implementation of this feature, I would make a PR for it.

@taion
Copy link
Contributor

taion commented Jul 15, 2019

Implementation-wise, we'd just add an extra check around

if (push) {
window.history.pushState(browserState, null, path);
} else {
window.history.replaceState(browserState, null, path);
}
. If the URL looks like an absolute URL (probably "contains :// or starts with //"), then we'd use location.assign or location.replace.

@ignatevdev
Copy link
Author

ignatevdev commented Jul 15, 2019

Do we want to add this only to the BrowserProtocol or maybe to HashProtocol as well?

@taion
Copy link
Contributor

taion commented Jul 15, 2019

Hmm, it's sort of "obvious" to me that this should work for BrowserProtocol (but only if state is empty). I'm not sure about for HashProtocol. Would you expect this to work there?

@ignatevdev
Copy link
Author

Even though there are very few people using hash-routing nowadays, I think that the case with the external redirects may also apply to those people, so I'd add it to the HashProtocol too.

@taion
Copy link
Contributor

taion commented Jul 15, 2019

Sounds good to me, then.

Technically this could also work as a middleware that you would use on the client side, and just handle the navigation action before it hits the protocol. Then it could just be plugged into whatever context.

@ignatevdev
Copy link
Author

Yeah, I really like the middleware approach.

What could be the name of this middleware then?

@taion
Copy link
Contributor

taion commented Jan 28, 2020

Sorry, I lost track of this. Something like externalNavigationMiddleware maybe?

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

2 participants