This repository was archived by the owner on Apr 8, 2020. It is now read-only.
This repository was archived by the owner on Apr 8, 2020. It is now read-only.
Angular2 PreRendering not working correctly when base href set to subdirectory #1049
Closed
Description
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 withapp.UseMvc();
. This means that only routes I've explicitly defined will be mapped. - Added
[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.) - 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
Metadata
Metadata
Assignees
Labels
No labels