Skip to content

Blazor Component Embedded in Razor Page #9834

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

Closed
CarrotSolutions opened this issue Apr 29, 2019 · 7 comments · Fixed by #10062
Closed

Blazor Component Embedded in Razor Page #9834

CarrotSolutions opened this issue Apr 29, 2019 · 7 comments · Fixed by #10062
Assignees
Labels
area-blazor Includes: Blazor, Razor Components bug This issue describes a behavior which is not expected - a bug. Done This issue has been fixed

Comments

@CarrotSolutions
Copy link

Repo: https://github.com/CarrotSolutions/WebApplication1.git

Please Help! We created a basic template razor page app. We added Blazor components. We have no problem getting this to work via replicating the steps in the 04/16 Blazor Update video or using the Blazor documentation. However, once we add the Blazor component to a Razor page, all of our asp-page links no longer work. The url changes in the address bar, but we remain on the same page. The startup file is as follows:

public void ConfigureServices(IServiceCollection services)
        {
            services.Configure<CookiePolicyOptions>(options =>
            {
                options.CheckConsentNeeded = context => true;
            });


            services.AddRazorPages()
                .AddNewtonsoftJson();

            services.AddServerSideBlazor();
        }

        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();

            app.UseCookiePolicy();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapRazorPages();
                endpoints.MapBlazorHub();
            });
        }

Page with working Component and broken link


<a asp-page="./Index">Home</a>

<br /> 

<div id="Counter"> 
    @(await Html.RenderComponentAsync<Counter>()) 
    <script src="~/_framework/blazor.server.js">
</script> 

@pranavkm pranavkm added area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates area-blazor Includes: Blazor, Razor Components labels Apr 29, 2019
@CarrotSolutions
Copy link
Author

I can replicate this scenario in any standard MVC or Razor Page default template. Link to a page with a Blazor component and all of the other page links will no longer function. You can even replicate the same situation using the boilerplate template app for a Blazor Server Side app and linking to any mvc view or razor page. All links no longer work. This has to be a Startup issue. Removing
endpoints.MapBlazorHub(); will allow the links to work again but obviously that breaks the Blazor component.

@CarrotSolutions
Copy link
Author

@stavroskasidis
Copy link

I can also replicate this. I guess it has something to do with the client-side router, probably hijacking the url changes and trying to resolve them to components.

@CarrotSolutions
Copy link
Author

Exactly, The capability of being able to use Blazor components inside of existing Razor or MVC apps is where this tech will gain traction in the beginning . Note, I also tried mapping the razor pages inside Startup, verifying all pages has unique routes, etc. Nothing works.

@chrdlx
Copy link

chrdlx commented May 7, 2019

I also replicated this using razor pages.

@pranavkm pranavkm added bug This issue describes a behavior which is not expected - a bug. cost: S and removed investigate labels May 8, 2019
@mkArtakMSFT mkArtakMSFT removed area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates labels May 9, 2019
@pranavkm pranavkm added Done This issue has been fixed and removed 2 - Working labels May 17, 2019
pranavkm added a commit that referenced this issue May 17, 2019
* Defer link interception until Router is initialized

Fixes #9834
@chrdlx
Copy link

chrdlx commented May 18, 2019

Just curious, when an issue like this is CLOSED, does it mean that if I download the latest master, should it be fixed? Thanks

@danroth27
Copy link
Member

@chrdlx Yes, but potentially with some latency as it takes some time for all the ASP.NET Core bits to make their way into the .NET Core SDK builds: https://github.com/aspnet/AspNetCore/blob/master/docs/DailyBuilds.md

@ghost ghost locked as resolved and limited conversation to collaborators Dec 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components bug This issue describes a behavior which is not expected - a bug. Done This issue has been fixed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants