Currently I have routes set up something like
const routes: Routes = [
{path: "", redirectTo: "route1", pathMatch: "full"},
{path: "route1", children: [
{path: "", redirectTo: "subRoute1", pathMatch: "full"},
{path: "subRoute1", component: SubRouteComponent}
]}
]
Which redirects to {domain}/route1/subRoute1 with accessing just {domain}.
Then in my components I have something like
<a [routerLink]="['/route1/subRoute1']">Link</a>
=============================
MY PROBLEM:
=============================
I want to add a new root url path to the entire app that is applied to all routes, but I don't want to have to go change all [routerLink] instances to point to this new path.
So for example, I want to change the routing like so, where site1 is the new root url path:
const routes: Routes = [
{path: "", redirectTo: "site1", pathMatch: "full"},
{path: "site1", children: [
{path: "", redirectTo: "route1", pathMatch: "full"},
{path: "route1", children: [
{path: "", redirectTo: "subRoute1", pathMatch: "full"},
{path: "subRoute1", component: SubRouteComponent}
]}
]}
]
And then I'd have to change routerLinks to
<a [routerLink]="['/site1/route1/subRoute1']">Link</a>
As far as I know, I would have to change all [routerLink] instances in the code to reflect this new url path change, WHICH I'M TRYING TO AVOID.
I could potentially have 100s of [routerLink] references, on top of needing the ability to change that root path often.
The solution I'm trying to work on right now is detecting a "NavigationStart" routing call and modifying the path at that point to prepend the new root path, but I don't think it's going to work like I hoped.
Also, this is another way of handling it: https://angular.io/guide/router#changing-heroes-to-superheroes
But I want to avoid having a bloated routing config.