@Farid Uddin Kiron MSFT
No I dont have any error
but i want load not found component content without navigation to not found page and without change url
like this : example for not found page
its's not change url just load content
not found page
How Redirect To Not Found Without Change Url In Blazor .Net 8
Hi,
How to redirect user to not found when page is not exists without change url in blazor ?
Like this link : git not found
3 answers
Sort by: Most helpful
-
Mahdi Elahi 31 Reputation points
2024-01-16T19:27:08.6133333+00:00 -
Bruce (SqlWork.com) 65,576 Reputation points
2024-01-16T23:56:22.6433333+00:00 just follow the docs and a not found component to the <Router>
<Router ...> ... <NotFound> ... </NotFound> </Router>
see docs:
https://zcusa.951200.xyz/en-us/aspnet/core/blazor/fundamentals/routing?view=aspnetcore-8.0
-
S Luiten 0 Reputation points
2024-09-26T14:06:41.75+00:00 The solution is to use
NotFound
in combination withUseStatusCodePagesWithReExecute
:Step 1: Add the following to Program.cs
app.UseHttpsRedirection(); // Add this line app.UseStatusCodePagesWithReExecute("/not-found"); app.UseStaticFiles(); ...
Step 2: Add a dummy .razor page with the same url
@page "/not-found" <My404Component />
Step 3: Add a NotFound renderfragment to Routes.razor
<Router> <Found> ... </Found> <NotFound> <LayoutView Layout="typeof(MyLayout)"> <My404Component /> </LayoutView> </NotFound> </Router>
The documentation states NotFound in Router is no longer supported, but this is actually not true, it still works but only if you do step 1 and 2 first, see https://github.com/dotnet/aspnetcore/issues/51203#issuecomment-1992085307