Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

angular dupicate url when routing

duplicate UR: ERROR Error: Uncaught (in promise): Error: NG04002: Cannot match any routes. URL Segment: ‘user/catalog/user/guide’

created user routing module:

const routes: Routes = [
  {
    path: 'user/catalog',
    component:TestCatalogComponent
  },
  {
    path:'user/guide',
    component:TestGuideComponent
  }
]

@NgModule({
  imports: [
    RouterModule.forChild(routes)
  ],
  exports:[RouterModule]
})
export class UserRoutingModule { }

app routing

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

const routes: Routes = [];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule { }

nav html:

<li class="nav-item">
<a class="nav-link" routerLinkActive="active" routerLink="user/catalog">Test Catalog</a>
</li>
<li class="nav-item">
<a class="nav-link" routerLinkActive="active" routerLink="user/guide">Testing Guide</a>
</li>

app component html

<app-header></app-header>
<router-outlet></router-outlet>

index.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title>MOAT</title>
    <base href="/" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <link rel="icon" type="image/x-icon" href="assets/image/favicon.png" />
    <!-- bootstrap -->
    <!-- script -->
    </head>
  <body class="mat-typography">
    <app-root></app-root>
  </body>
</html>

my index html has base href="/", any other advice?

>Solution :

Router links should start with a /, otherwise they get appended to the current link:

<li class="nav-item">
<a class="nav-link" routerLinkActive="active" routerLink="/user/catalog">Test Catalog</a>
</li>
<li class="nav-item">
<a class="nav-link" routerLinkActive="active" routerLink="/user/guide">Testing Guide</a>
</li>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading