Aspnetcore: [Blazor] UriHelper.NavigateTo with Parameters from a layout, requires the current page to have the same parameter (with repro step)

Created on 1 Jun 2019  路  7Comments  路  Source: dotnet/aspnetcore

Describe the bug

This issue contains repro steps for #7023 When you invoke NavigateTo from a layout, it tries to parse the target url pattern with the current page. So this kind of exception is raised " Object of type 'Toss.Client.Pages.Home.Index' does not have a property matching the name 'tag'. ". But the page is loaded correctly.

To Reproduce

  • Last version of SDK and docker installed
  • git clone https://github.com/RemiBou/Toss.Blazor.git
  • cd Toss.Blazor
  • git checkout origin/pure-css-no-bootstrap
  • docker-compose up -d ravendb
  • cd Toss.Server
  • dotnet run
  • navigate to the root of the app on your browser (http://localhost:52386) then enter something on the textbox in the layout, the error message should be displayed bellow the menu

If you have any trouble with the repro steps please ask

Expected behavior

The navigation occurs without the error.

area-blazor bug

All 7 comments

@danroth27

Here are easier step for repro

git clone https://github.com/RemiBou/Toss.Blazor.git
cd Toss.Blazor
git checkout origin/pure-css-no-bootstrap
cd Toss.Tests.E2E
dotnet test

You will see the error message displayed on the web page during the e2e tests

OK, I see the error:

image

Here's the relevant code from the layout:

https://github.com/RemiBou/Toss.Blazor/blob/pure-css-no-bootstrap/Toss.Client/Shared/Layouts/MainLayout.razor

@inject IExceptionNotificationService exceptionNotificationService;
@inject IAccountService accountService;
@inject IHttpApiClientRequestBuilderFactory ClientFactory;
@inject IUriHelper urlHelper;
@implements IDisposable;
@inject IMessageService messageService;
<div class="pure-g">
    <div class="top-menu pure-menu pure-u-5-5 pure-menu-horizontal pure-menu-scrollable">
        <a href="#" class="pure-menu-link pure-menu-heading">Toss</a>
        <ul class="pure-menu-list">
            @if (_account != null)
            {
                <li class="pure-menu-item">
                    <NavLink href="/account" class="pure-menu-link" id="LinkAccount">
                        <Icon Title="Account" IconType="person"></Icon>
                    </NavLink>
                </li>

            }
            else
            {
                <li class="pure-menu-item">
                    <NavLink href="/login" class="pure-menu-link" id="LinkLogin">
                        Login
                    </NavLink>
                </li>
            }
            <li class="pure-menu-item">
                <NavLink href="/new" class="pure-menu-link" id="LinkNewToss">
                    <Icon Title="New Toss" IconType="edit"></Icon>
                </NavLink>
            </li>
            @if (_account != null)
            {
                @foreach (var hashTag in _account.Hashtags ?? new List<string>())
                {
                    <li class="pure-menu-item">
                        <NavLink href=@("/tag/"+hashTag) Match="NavLinkMatch.All" class="pure-menu-link  tag-link">
                            #@hashTag
                        </NavLink>
                    </li>
                }
            }
            <li class="pure-menu-item">
                <div class="pure-form">
                    <EditForm OnValidSubmit="SeeHashtag" Model="@addHashtagCommand">
                        <MyInput Placeholder="Tag" Type="text" Id="TxtAddHashTag" bind-Value="@addHashtagCommand.NewHashTag" />
                    </EditForm>
                </div>
            </li>
        </ul>
    </div>
</div>
<Message />
<div class="main">
    @Body
</div>
@functions {

    [Parameter]
    RenderFragment Body { get; set; }


    AddHashtagCommand addHashtagCommand = new AddHashtagCommand();

    private AccountViewModel _account;
    protected override void OnInit()
    {
        this.exceptionNotificationService.OnException += HandleExceptions;
        this.accountService.SubscribeOnCurrentAccountChanged(this.OnAccountChanged);
        base.OnInit();
    }

    private void OnAccountChanged(object sender, AccountViewModel account)
    {
        this._account = account;
        this.StateHasChanged();
    }
    private void HandleExceptions(object sender, string s)
    {
        messageService.Error(s);
    }
    public void Dispose()
    {

        this.exceptionNotificationService.OnException -= HandleExceptions;
    }
    protected void SeeHashtag()
    {
        urlHelper.NavigateTo("/tag/" + addHashtagCommand.NewHashTag);
    }
}

@danroth27 I think the error is gone with preview6, did you change anything between 5 and 6 that could have impacted this ?

@RemiBou It's certainly sounds like we did :smile:. @SteveSandersonMS?

I don't know of anything specific we changed for this. Maybe the exact details of your repro scenario rely on something more obscure I can't anticipate.

Closing as looks like this is fixed.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

reduckted picture reduckted  路  91Comments

oliverjanik picture oliverjanik  路  91Comments

natemcmaster picture natemcmaster  路  213Comments

davidfowl picture davidfowl  路  126Comments

kevinchalet picture kevinchalet  路  761Comments