Angular 8-路由器导航到组件,但不更改URL

时间:2020-02-24 20:59:20

标签: angular angular-router

我已经看过this个帖子,添加了{useHash: true},但是它不能解决我的问题。我能够导航到该组件,但是URL永远不会改变。它停留在托管它的localhost:4211。我也无法手动输入localhost:4211/atm之类的URL来路由到该组件。我相信URL和路由器之间存在断开连接。

const routes: Routes = [
  {
    path: "", 
    component: HomeComponent,
    pathMatch: "full"
  },
  {
    path: "home", 
    component: HomeComponent,
  },
  {
    path: "atm", 
    component: AtmFormPageComponent,
  }
];

@NgModule({
  imports: [RouterModule.forRoot(routes, { useHash: true, enableTracing: true })],
  exports: [RouterModule]
})
export class AppRoutingModule { }
<div class="navbar-collapse" id="navbarColor01">
    <ul class="navbar-nav mr-auto">
      <li class="nav-item">
        <a class="nav-link" routerLink="/home" >Home</a>
      </li>
      <li class="nav-item">
        <a class="nav-link" routerLink="/atm" >atm</a>
      </li>

我已导入路由器模块,并且控制台或网络中没有错误。

0 个答案:

没有答案