Blazor WebAssembly navigation behaves differently after publish
See original GitHub issueIs there an existing issue for this?
- I have searched the existing issues
Describe the bug
Hi,
Why the Blazor WebAssembly application recognizes/navigate to the same url differently before and after publish?
Please find the steps to reproduce below.
Expected Behavior
After click on the “Click me” button response from controller should be displayed when debugging and after publish. OR After click on the “Click me” button Blazor page should be displayed when debugging and after publish
Steps To Reproduce
- Create a new Blazor WebAssembly project using Visual Studio 2022
- Select .NET 6 as Target Framework and Authentication Type as “None”
- Select all available options (Configure fo HTTPS, ASP.NET Core Hosted, Progressive Web Application, Do not use top-level statements)
- Replace code from Counter.razor file in the *.Client project with the following code:
@page "/counter"
@inject NavigationManager navigationManager;
<PageTitle>Counter</PageTitle>
<h1>Counter</h1>
<p role="status">Current count: @currentCount</p>
<a class="btn btn-primary" href="@GetUrl()">Click me</a>
@code {
private int currentCount = 0;
private void IncrementCount()
{
currentCount++;
}
private string GetUrl()
{
return navigationManager.BaseUri + "WeatherForecast";
}
}
Case 1
- Build & Run the *.Server project using Visual Studio 2022
- Click on the Counter tab
- Click on the “Click me” button
Result: JSON response will be displayed in the browser window
Case 2
- Build & Publish the *.Server project using Folder Publish Profile Example profile configuration:
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project>
<PropertyGroup>
<DeleteExistingFiles>true</DeleteExistingFiles>
<ExcludeApp_Data>false</ExcludeApp_Data>
<LaunchSiteAfterPublish>true</LaunchSiteAfterPublish>
<LastUsedBuildConfiguration>Debug</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<PublishProvider>FileSystem</PublishProvider>
<PublishUrl>bin\Debug\net6.0\publish\</PublishUrl>
<WebPublishMethod>FileSystem</WebPublishMethod>
<_TargetId>Folder</_TargetId>
<SiteUrlToLaunchAfterPublish />
<TargetFramework>net6.0</TargetFramework>
<ProjectGuid>ee6cacb6-0f5e-4f9c-ad63-49be7dce6c97</ProjectGuid>
<SelfContained>false</SelfContained>
</PropertyGroup>
</Project>
- Deploy the published files to IIS or run the application from *.Server.exe file created in publish folder
- Go to the application url in a browser
- Click on the Counter tab
- Click on the “Click me” button
Result: “Sorry, there’s nothing at this address.” message will be displayed.
Additional Step: After the “Sorry, there’s nothing at this address.” is displayed, click CTRL + F5
Result: JSON response will be displayed in the browser window
Exceptions (if any)
No response
.NET Version
6.0.401
Anything else?
Issue Analytics
- State:
- Created a year ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
ASP.NET Core Blazor routing and navigation
This article explains how to manage Blazor app request routing and how to use the NavLink component to create navigation links.
Read more >Host and deploy ASP.NET Core Blazor WebAssembly
Learn how to host and deploy Blazor WebAssembly using ASP.NET Core, Content Delivery Networks (CDN), file servers, and GitHub Pages.
Read more >5 Reasons Why You Should Replace the Default ...
This blog explains the reasons and steps to replace the default navigation menu in your Blazor app with the Syncfusion Sidebar component.
Read more >Avoid 'multi steps refreshing' on page transition in Blazor ...
It means that each component load his content (nearly) independently form other components. Therefore when navigation occurs and the new active ...
Read more >Cant directly go to a different blazor page : r/dotnet
After you add a new page/component, assuming its page attribute (route) is set properly, if the browser does not get the updated WASM,...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@Tonrin17 there are two different service-workers used in development and production. They are both in your app, you can check them out. The development service worker just no-ops.
Also debugging might affect the environment since a special version of Edge/Chrome is launched for the debugger to work.
Not in this example, but in other project I tried Debug, Release and some other custom configurations. Also have tried runtimes like Portable or Win-x86