saka
saka

Reputation: 83

Angular2 Routing 3.0.0x Get Errors for style.css when using parameters

I'm in Angular2 with the latest Router package (3.0.0.8?)

When I add a parameter to one of my routes, the page can no longer find all the necessary style and app files.

When I have this:

export const routes: RouterConfig = [
    {path: '', component: LandingPageComponent },
    { path: 'buyers', component: BuyerFormComponent },
    {path: 'links', component: GenerateLinksComponent},
    {path: 'cc/:bid', component: SupplierFormComponent}
];

When I navigate to "http://localhost:3000/cc/b4" I get a bunch of errors:

GET http://localhost:3000/cc/styles.css
GET http://localhost:3000/cc/app etc

My other routes without parameters work fine and if I remove the parameter from the route:

export const routes: RouterConfig = [
    {path: '', component: LandingPageComponent },
    { path: 'buyers', component: BuyerFormComponent },
    {path: 'links', component: GenerateLinksComponent},
    {path: 'cc', component: SupplierFormComponent}
];

And visit the route without a parameter (localhost3000/cc), the page loads fine.

I have the href="." in my index.html as such:

<html>
  <head>

    <base href=".">

Any suggestions? Thank you!

Upvotes: 0

Views: 69

Answers (1)

G&#252;nter Z&#246;chbauer
G&#252;nter Z&#246;chbauer

Reputation: 658087

The new router requires

<base href="/">

Empty path routes usually should have set terminal: true

{path: '', component: LandingPageComponent, terminal: true },

In beta.9 terminal: true will be replaced by

{path: '', component: LandingPageComponent, pathMatch: full },

https://github.com/angular/angular/blob/master/modules/@angular/router/src/config.ts#L258

Upvotes: 0

Related Questions