You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 8, 2020. It is now read-only.
I'm trying to make PreRendering work with an Angular2 app based in a subdirectory.
Steps to recreate:
Created a new project from the Microsoft SPA Templates dotnet new angular -n DashboardTest (dotnet new --install Microsoft.AspNetCore.SpaTemplates::* to install the templates package)
Removed all routing from Startup.cs and replaced with app.UseMvc();. This means that only routes I've explicitly defined will be mapped.
Added [Route("/dashboard/{*angularRoute}")] attribute to the Index() action on the HomeController to catch all requests to my chosen subdirectory of /dashboard and pre-render the angular app (the Home/Index view already contains <app asp-prerender-module="ClientApp/dist/main-server">Loading...</app> for pre-rendering.)
Updated the base href tag in _Layout.cshtml to <base href="https://github.com/dashboard" /> to correctly configure the angular app to treat /dashboard as it's root.
On the surface everything appears to work beautifully, however behind the scenes the pre-rendering has broken. To prove this, load view-source:http://localhost:5000/dashboard/counter (in Chrome) - you'll see the rendered output is actually the /home route, not the /counter route as expected.
Suggested fix:
Add public string BaseHref { get; set; } and unencodedPathAndQuery = !string.IsNullOrEmpty(BaseHref) && unencodedPathAndQuery.StartsWith(BaseHref) ? unencodedPathAndQuery.Substring(BaseHref.Length) : unencodedPathAndQuery; to PrerenderTagHelper
The text was updated successfully, but these errors were encountered:
I'm trying to make PreRendering work with an Angular2 app based in a subdirectory.
Steps to recreate:
dotnet new angular -n DashboardTest
(dotnet new --install Microsoft.AspNetCore.SpaTemplates::*
to install the templates package)Startup.cs
and replaced withapp.UseMvc();
. This means that only routes I've explicitly defined will be mapped.[Route("/dashboard/{*angularRoute}")]
attribute to theIndex()
action on theHomeController
to catch all requests to my chosen subdirectory of /dashboard and pre-render the angular app (theHome/Index
view already contains<app asp-prerender-module="ClientApp/dist/main-server">Loading...</app>
for pre-rendering.)_Layout.cshtml
to<base href="https://github.com/dashboard" />
to correctly configure the angular app to treat/dashboard
as it's root.On the surface everything appears to work beautifully, however behind the scenes the pre-rendering has broken. To prove this, load
view-source:http://localhost:5000/dashboard/counter
(in Chrome) - you'll see the rendered output is actually the/home
route, not the/counter
route as expected.Suggested fix:
Add
public string BaseHref { get; set; }
andunencodedPathAndQuery = !string.IsNullOrEmpty(BaseHref) && unencodedPathAndQuery.StartsWith(BaseHref) ? unencodedPathAndQuery.Substring(BaseHref.Length) : unencodedPathAndQuery;
toPrerenderTagHelper
The text was updated successfully, but these errors were encountered: