Skip to content

Use relative path in NavigateTo#22146

Merged
guardrex merged 2 commits intodotnet:mainfrom
beppemarazzi:patch-1
Apr 27, 2021
Merged

Use relative path in NavigateTo#22146
guardrex merged 2 commits intodotnet:mainfrom
beppemarazzi:patch-1

Conversation

@beppemarazzi
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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