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

Use relative path in NavigateTo #22146

Merged
merged 2 commits into from
Apr 27, 2021
Merged

Use relative path in NavigateTo #22146

merged 2 commits into from
Apr 27, 2021

Conversation

beppemarazzi
Copy link
Contributor

In the code snippet provided as example of doing redirection for user selected culture, there was a NavigateTo with absolute path. This doesn't work if the app is behind a reverse proxy in some virtual subfolder.

In the code snippet provided as example of doing redirection for user selected culture, there was a NavigateTo with absolute path. This doesn't work if the app is behind a reverse proxy in some virtual subfolder.
@guardrex guardrex self-assigned this Apr 27, 2021
@guardrex
Copy link
Collaborator

@beppemarazzi ... Are you setting the app base path in this scenario? If so, then it should form the correct BaseUri and ultimately the correct path because the URI provided to NavigateTo is relative to to the BaseUri.

@guardrex
Copy link
Collaborator

guardrex commented Apr 27, 2021

I think instead of this change that a cross-link here will provide general assistance with in this use case. I'll make an update on this PR to cover it.

UPDATE: Done! Let's give this a shot. I'll continue to take feedback on it. 👂 If more devs write in on it, I'll seek to make an additional update and probably write a little text with the link and move the link to a NOTE under the example.

Thanks @beppemarazzi! 🚀

@guardrex guardrex merged commit 0756686 into dotnet:main Apr 27, 2021
@beppemarazzi
Copy link
Contributor Author

@beppemarazzi ... Are you setting the app base path in this scenario? If so, then it should form the correct BaseUri and ultimately the correct path because the URI provided to NavigateTo is relative to to the BaseUri.

@guardrex Yes, app base path is correctly set. But with the leading '/' the browser navigates to the absolute path ignoring the base path.
If i enter Blazor._internal.navigationManager.getBaseURI() in a browser console i get something like this "https://myserver/my/virtual/path/app/" (with a final '/')
In the same console Blazor._internal.navigationManager.navigateTo("something/else", true) navigates to https://myserver/my/virtual/path/app/something/else while Blazor._internal.navigationManager.navigateTo("/something/else", true) navigates to https://myserver/something/else

@guardrex
Copy link
Collaborator

Thanks for that clarification @beppemarazzi.

🤔 ... The API docs seem a bit weak on details. I expected different behavior and guessed wrong that the BaseUri would be the root ... that the presence of the leading slash would be from the root using the virtual path. Without the leading slash, I expected the path to form from the path where the component resides.

It doesn't seem like there is any harm in removing the forward slash. I'll put up a PR in a minute to patch that as you originally suggested. I've also made a note on my UE ("User Experience," i.e., total overhaul+updates) tracking issue to take a closer look at this subject when I reach the Host and Deploy overview. I think the docs need a careful assessment on how NavigateTo is covered and what examples the docs are showing.

@beppemarazzi
Copy link
Contributor Author

Just found this dotnet/aspnetcore#25204...

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