Angular 7 routing ignore path

893 views Asked by At

I have an Angular 7 application, running .Net Core on the back end. I have the following routes defined:

const routes: Routes = [ 
  { path: 'home', component: HomeComponent },
  { path: 'login', component: LoginComponent },
  { path: 'about', component: AboutComponent },
  { path: '**', redirectTo: 'home' } 
];

In Visual Studio 2019, this is running at https://localhost:44358.

All works as expected.

But now I want to get metadata for a SAML implementation using sustainsys.saml2.aspnetcore2. To get the metadata file, I try to enter https://localhost:44358/Saml2/ in my browser. As expected, because the path does not match anything defined, the default route takes over and I am routed to the home page.

I removed the final path, so I no longer had any default routing for unmatched paths, and then it worked fine to get the metadata.

My question is: Is there any way to redirect to 'home' for all unmatched paths except some configured path (or paths), which would just be ignored as if the default route were not present?

1

There are 1 answers

0
Alex Steinberg On

Rather add a path to your base-href in index.html (e.g. <base href="/app/"/>) so that the Angular Router won't pick up paths on your root, then you'll be able to keep your wildcard redirect as is and /Saml2/ won't be intercepted.

Of course, if the app is already in production and you need to preserve URLs, you might not be in a position to make this kind of change.