Blazor: Implementing 404 not found page

末鹿安然 提交于 2019-12-03 08:28:49

Try this: App.cshtml

<Router AppAssembly=typeof(Program).Assembly FallbackComponent="typeof(Error404)" >

Create a Component named Error404.cshtml

Note: This is only a guess I gathered from digging the Router class. See https://github.com/aspnet/AspNetCore/blob/343208331d9ebbb3a67880133f4139bee2cb1c71/src/Components/src/Microsoft.AspNetCore.Components/Routing/Router.cs

Please, let me know if it works for you.

In App.razor, add the <NotFound> element under <Router>and set what content you'd like to be displayed when Blazor can't find the specified route.

For example:

<Router AppAssembly="typeof(Program).Assembly">
    <NotFound>
        <h1>404 Not Found</h1>
    </NotFound>
</Router>

(Note: If it's a server side app, then it would be typeof(Startup).Assembly)

Edit: Changed <NotFoundContent> to <NotFound>

Source

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!