Skip to content

Blazor - Navigate away from blazor client App #11058

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

Closed
dazinator opened this issue Jun 10, 2019 · 5 comments
Closed

Blazor - Navigate away from blazor client App #11058

dazinator opened this issue Jun 10, 2019 · 5 comments
Labels
area-blazor Includes: Blazor, Razor Components

Comments

@dazinator
Copy link

dazinator commented Jun 10, 2019

Is your feature request related to a problem? Please describe.

Suppose you want to navigate away from a blazor app (base path: /) to an mvc / razor page hosted on the same host: /foo

I don't think you can currently do this very easily in a blazor client application, and this is problematic.
This is because all navigation performed within the blazor app is set to be relative to the base path (in this case /) and in addition, the blazor client-side router takes full ownership of all URLs under the base path, so therefore, no navigation can escape the router.

Describe the solution you'd like

A simple way to navigate away from the blazor client side app, bypassing the router.
Not fussy. Could be an optional boolean when making a Navigate call, to "bypass router"?

Perhaps this is already possible - if so please let me know the recommended mechanism.

Describe alternatives you've considered

I've considered using the Router's Fallback component (it routes to this component if it cant match any client side route) and implementing a component that uses js interop to do a browser.reload() at the given url where that component is displayed. I think this would work but it seems overly cumbersome. Also I'd like to distinguish between navigation that I explicitly do not want my SPA to handle (I.e when I know I am navigating away from the app) and a genuine client side routing mistakes where an intended client side navigation (within the app) could not be resolved for some reason. It would be beneficial to reserve the router fallback component for that second case, and have some mechanism of navigating that explicitly caters for the first case

Additional context

Note this is also a problem for architectures where you want multiple spa's hosted at different paths, and want to be able to navigate from /spa1 to /spa2 etc. All navigation from with /spa1 will have the base path /spa1 preserved and the same with /spa2. So an attempt to navigate from /spa1 to /spa2 actually just navigates to /spa1/spa2 and is handled by the client side router fallback component. In this case my idea above about using a fallback component to do a browser reload at that path wouldn't work so that's another reason I do not like it.

Also a similar problem occurs with http client - how can /spa1 blazor client app make a http request to /api? As due to the base path being set on http client requests to /api/ actually get sent to /spa1/api/. I can see a blazor app needing to make http calls to api outside if its url space as well as inside it, as needs require. Would be good to have some documentation as to golden path to achieve that.

@Eilon Eilon added the area-blazor Includes: Blazor, Razor Components label Jun 10, 2019
@pranavkm
Copy link
Contributor

@dazinator likely a dup of #9834. Could you try if your scenario works using the preview6 bits?

@dazinator
Copy link
Author

@pranavkm I can try with the preview6 stuff, I remain sceptical as the issue you linked is talking about server side blazor components, and I'm in a pure client side blazor app - still will try.

@SteveSandersonMS
Copy link
Member

You can navigate anywhere using root-relative URLs, e.g.:

<a href="/somewhere">Click me</a>

This will be independent of your <base href>.

If you're experiencing any issues with making this work in the preview 6 release, could you please post a new issue with minimal repro steps? Thanks!

@SteveSandersonMS
Copy link
Member

the blazor client-side router takes full ownership of all URLs under the base path, so therefore, no navigation can escape the router.

That's no longer the case since preview 6. There is still one known issue with it (#11099), but <a> tags should work fine.

@dazinator
Copy link
Author

Thanks for the update, it seems according to #11099 you can now do:

You could use NavigateTo("...", force)

To force a redirect. If so this is the capability I am looking for as I don't want to use tags. I'll try this out.

@ghost ghost locked as resolved and limited conversation to collaborators Dec 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components
Projects
None yet
Development

No branches or pull requests

4 participants