-
Notifications
You must be signed in to change notification settings - Fork 242
Blazor CRUD uses NotFound() method instead of navigation
#3162
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
base: main
Are you sure you want to change the base?
Conversation
javiercn
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we have the scaffolder create the NotFound page if it doesn't exist? Similarly, add the required code (UseStatusCodePages and NotFoundPageType)
|
Note that these changes are specific to .NET 10. For .NET 9 and earlier we'll need to continue to generate the existing code for handling not found responses. |
The three required additional changes to do that are:
<Router AppAssembly="typeof(Program).Assembly" NotFoundPage="typeof(Pages.NotFound)">
<Found Context="routeData">
<RouteView RouteData="routeData" DefaultLayout="typeof(Layout.MainLayout)" />
<FocusOnNavigate RouteData="routeData" Selector="h1" />
</Found>
</Router>
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error", createScopeForErrors: true);
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseStatusCodePagesWithReExecute("/not-found", createScopeForErrors: true); // ADD HERE
app.UseHttpsRedirection(); |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
@bleaphar, are you able to test the recent changes and confirm if they are correct? |
I was just able to test and verify that these changes are correct and scaffolding is working as intended. Here's a link to a sample repo I created: https://github.com/bleaphar/BlazorWebAppCRUD.git. If you examine the commit history, you can find the diff between how the template comes and post using these proposed changes. |
|
@bleaphar, thank you! Based on the Post Blazor CRUD Scaffolding commit we can see that the changes did not get applied correctly. We have e.g. I have one concern about the testing methodology. You probably did it on a non-edited template. These templates already contain some of the changes that we want scaffolder to apply. We can see, examining the "Post Blazor CRUD Scaffolding" commit, that indeed, my changes did not break any stuff but at the same time, none of the editions this PR is introducing was applied.
And then observe how they are getting added back. However, based on the current test, we already can see that the lines |
|
Or just test on a Blazor Web App originally created with .NET 9 and then retargeted to .NET 10. |
|
Note that we also need to version these scaffolding updates so that the .NET 9 version of the scaffolder is preserved. This is different from the old scaffolding system where each scaffolder version shipped as a separate package from a separate branch. With |
This PR is updating Blazor CRUD scaffolder to use
NavigationManager.NotFound()instead ofNavigationManager.NavigateTo("notfound"). I am not sure how to apply all the necessary changes. I will list all the actions needed and would be grateful for help in completing it, cc @deepchoudhery, @tlmii.Changes:
NavigateTo(\"notfound\")withNavigationManager.NotFound()Blazor CRUD.NotFound.razorpage to the project that could be same as https://github.com/dotnet/aspnetcore/blob/9a6b2eb7ee0eaffcdd3a361b06899b4fe735a4d6/src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWeb-CSharp/Components/Pages/NotFound.razorNotFoundPageparameter toRouter, like here:https://github.com/dotnet/aspnetcore/blob/9a6b2eb7ee0eaffcdd3a361b06899b4fe735a4d6/src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWeb-CSharp/Components/Routes.razor#L7
Fixes #3168