2

I have a simple application in which when I use parameter with routing direct after localhost path working fine, but when I click on different routing 'test2' it is able to change the path(http://localhost:4200/test2) but page is not redirecting to that routing, it remains in same page(home page) in my project. I am not able to debug actually what is happening. sample code below

app-routing.module.ts

import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { TestComponent } from './test/test.component';
import { Test2Component } from './test2/test2.component';

const routes: Routes = [
  {
    path: "",
    pathMatch: 'full',   
    component: TestComponent
  },
  {
    path: ":id",
    component: TestComponent
  },
  {
    path: "test2",   
    component: Test2Component
  },
 
];

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

1 Answer 1

2

you should put router-outlet in your app component (bootstrap):

<router-outlet></router-outlet>
Sign up to request clarification or add additional context in comments.

1 Comment

Its already there, I resolved that issue just we need to put { path: ":id", component: TestComponent }, in the last

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.