tjxx
tjxx

Reputation: 1

Opening New Tab in Blazor App Not Behaving as Expected

I ran into an issue with my Blazor app in which I'm trying to open a page in a new tab and while it does open the page, it's adding extra characters to the URL for some reason. The directive at the top is this:

@page "folder/mypage"

In my app I'm opening the tab like this:

await _jsRuntime.InvokeAsync<object>("open", "folder/mypage", "_blank");

But the URL displays like this:

myapp.com/folder/folder/mypage

I'm not sure what I'm missing or doing wrong and would appreciate any help I can get on this.

Upvotes: 0

Views: 1446

Answers (1)

tjxx
tjxx

Reputation: 1

I solved it and am surprised I didn't see this sooner.

Because the page already had /folder in the URL and I was trying to load the new tab with "folder/mypage", this caused it to add the second "folder" to the URL. I updated the JS Interop and page directive code to the following and it works correctly now.

At the top of the page I've updated the directive to:

@page /mypage

In my JS Interop call:

await _jsRuntime.InvokeAsync<object>("open", "mypage", "_blank");

Upvotes: 0

Related Questions