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

[Blazor] Attempting to navigate to URI with fragment causes Microsoft.AspNetCore.Components.NavigationException server-side #14464

Closed
xperiandri opened this issue Sep 26, 2019 · 12 comments
Assignees
Labels
area-blazor Includes: Blazor, Razor Components ✔️ Resolution: By Design Resolved because the behavior in this issue is the intended design.

Comments

@xperiandri
Copy link

Describe the bug

Attempting to navigate to address with fragment like https://localhost:44317/product/abc#General-information in server-side Blazor causes Microsoft.AspNetCore.Components.NavigationException

To Reproduce

  1. Using this version of ASP.NET Core 3.0 RTM
  2. Create a page with a button that navigates to the same URI but with a fragment
protected override void OnInitialized()
{
    var uri = new Uri(navigationManager.Uri);
    var fragment = uri.Fragment;
    if (fragment != "#fragment")
        navigationManager.NavigateTo(GenerateTabLink("#fragment"));
    else
        selectedTab = fragment;
}
private string GenerateTabLink(string tabFragment)
{
    var builder = new UriBuilder(new Uri(navigationManager.Uri, UriKind.RelativeOrAbsolute))
    {
        Fragment = tabFragment
    };
    return builder.ToString();
}
  1. See error Microsoft.AspNetCore.Components.NavigationException

Expected behavior

Component navigates to the same page with the added fragment

@xperiandri
Copy link
Author

Ah, I got it. navigationManager.Uri return URL without fragment. But URL in browser contains a fragment. This way navigation happens to the same URL.

@mkArtakMSFT mkArtakMSFT added area-blazor Includes: Blazor, Razor Components investigate labels Sep 26, 2019
@mkArtakMSFT mkArtakMSFT added this to the 5.0.0-preview1 milestone Sep 26, 2019
@mkArtakMSFT
Copy link
Member

Thanks for contacting us, @xperiandri.
Can you please share a complete sample app (ideally as a GitHub repo) so that we can investigate it?

@mkArtakMSFT mkArtakMSFT added the Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. label Sep 26, 2019
@kmuthukumar23
Copy link

Hi @mkArtakMSFT

I am also facing the same issue when using the Urihelper.

I have switched to 'Release' mode, then it works perfectly. But i have no idea about how it is worked in 'Release' and not work in 'Debug' mode.

Any thoughts regard this?

@mkArtakMSFT
Copy link
Member

@kmuthukumar23 please provide a minimal repro project, so we can investigate this.

@kmuthukumar23
Copy link

Hi @mkArtakMSFT

Here is the Sample.

navIssue.zip

Steps to reproduce:

  1. open the project in vs 2019 preview
  2. Run it.
  3. It will throws the following
    image

i have used vs 2019 16.4 preview 1 and .net core 3.0.100

@mkArtakMSFT
Copy link
Member

@javiercn is this something you have context about?

@javiercn
Copy link
Member

javiercn commented Oct 7, 2019

@kmuthukumar23 I can't repro this behavior with your repro. I'm using RTM bits, is there any special url you are using?

@kmuthukumar23
Copy link

kmuthukumar23 commented Oct 8, 2019

Hi @javiercn

I have just set the initial loading URL in 'index.razor' by using 'UriHelper'. In default blazor app, it navigates to 'pages/index.razor'. Now i am override it to navigate to 'pages/counter.razor' by using 'UriHelper' in 'index.razor'.

in index.razor, i have modified like below.

@using Microsoft.AspNetCore.Components

@Inject Microsoft.AspNetCore.Components.NavigationManager UriHelper

Hello, world!

Welcome to your new app.

@code{

protected override void OnInitialized()
{
    UriHelper.NavigateTo("Counter");
}

}

@javiercn
Copy link
Member

javiercn commented Oct 8, 2019

That works for me without issue. I’m using RTM bits

@kmuthukumar23
Copy link

Hi @javiercn

I have attached video for this. Please check it.

https://drive.google.com/file/d/1-0MhbpapthHneN4GkTP1Br9XWidl38gZ/view?usp=sharing

@javiercn
Copy link
Member

@kmuthukumar23 That exception is expected, that's how the component signal that a redirection needs to happen.

You have first chance exceptions turned on, that's why you are seeing the debugger break on the exception. If you press F5 you'll see that you are correctly redirected to the /counter page and that it gets rendered successfully.

You can configure the debugger to avoid breaking on this exception as follows:
image

@javiercn
Copy link
Member

@kmuthukumar23 Thanks for the video showcasing your issue.

We've determined that this behavior is by design, follow the instructions above to avoid breaking on this exception type.

We are closing this issue as the behavior is by design and there's no further action to be taken here.

@javiercn javiercn added ✔️ Resolution: By Design Resolved because the behavior in this issue is the intended design. and removed investigate Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. labels Oct 10, 2019
@ghost ghost locked as resolved and limited conversation to collaborators Dec 2, 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 ✔️ Resolution: By Design Resolved because the behavior in this issue is the intended design.
Projects
None yet
Development

No branches or pull requests

4 participants