我正在尝试使用参数导航到page
,但似乎不起作用。
我收到错误消息:
blazor.webassembly.js:1 Uncaught (in promise) Error: System.InvalidOperationException: 'Router' cannot find any component with a route for '/home/+HhbuYzG1j5j/lzjL2gUUYdA5HgM0KYVTx55NYBuYLkYyMOImyVT8627J1iRAkCxjY2ZOAtoA/PuL2dePKX8+qSngAsymb6k010UIk8IG+p7/SlX2PTKEtyVVUXWqgstdmaIn95MXyV0w1XEHYXHm3rv1L5CwIicFtg8b8Vpkng='.
at Microsoft.JSInterop.DotNetDispatcher.InvokeSynchronously (:8300/System.String assemblyName, System.String methodIdentifier, System.Object targetInstance, System.String argsJson) <0x2a4a160 + 0x001bc> in <af36ed9192be4a95b907125ccf0c1e59>:0
at Microsoft.JSInterop.DotNetDispatcher.BeginInvoke (:8300/System.String callId, System.String assemblyName, System.String methodIdentifier, System.Int64 dotNetObjectId, System.String argsJson) <0x2a49d08 + 0x00088> in <af36ed9192be4a95b907125ccf0c1e59>:0
at endInvokeDotNetFromJS (blazor.webassembly.js:1)
发件人
@page "/"
@using Microsoft.AspNetCore.Blazor.Services;
@inherits AuthBase
<input type="text" bind="@Username" />
<button type="button" onclick="@AuthAsync">Authenticate</button>
发件人逻辑
public class AuthBase : BlazorComponent {
[Inject]
protected IUriHelper uriHelper { get; set; }
[Inject]
protected AuthService authService { get; set; }
public string Username { get; set; }
public string url = "/home";
public async Task AuthAsync() {
var ticket = await this.authService.AuthenticateAsync(Username);
if (ticket.Value == string.Empty) {
Console.WriteLine("Ticket invalid,retry !");
return;
}
var urlToSend = url + "/" + ticket.Value;
Console.WriteLine("Sending to:" + urlToSend);
uriHelper.NavigateTo(urlToSend);
}
}
接收器
@page "/home/{Ticket}"
@inherits HomeBase
接收器逻辑
public class HomeBase:BlazorComponent {
[Parameter]
private string Ticket { get; set; }
}
我不知道我希望被调用的网址是/home/[ticketvalue]
,而且从错误中可以看出它是正确的。
为什么不起作用?
答案 0 :(得分:1)
问题是您的Ticket
值包含斜杠/