routerLink有时不路由到默认路由

时间:2019-01-16 10:40:50

标签: angular angular-routing

这是我的默认路线:

  {
    path: '',
    component: HomeComponent
  },

当我有时通过单击next按钮<button [routerLink]="['/']" mat-raised-button color="primary">next</button>来路由到默认路由时,它不起作用。

总是单击next时,我只是被重定向到当前路线。然后必须再次单击next按钮,这样我才能进入home

任何想法为什么会发生?

更新: 刚刚将我的button更改为a-<a [routerLink]="['/']" mat-raised-button color="primary">next</a>,但还是同样的问题。

版本

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.12.1
@angular-devkit/build-angular     0.12.1
@angular-devkit/build-optimizer   0.12.1
@angular-devkit/build-webpack     0.12.1
@angular-devkit/core              7.2.1
@angular-devkit/schematics        7.2.1
@angular/cdk                      7.2.1
@angular/cli                      7.2.1
@angular/flex-layout              7.0.0-beta.23
@angular/material                 7.2.1
@ngtools/webpack                  7.2.1
@schematics/angular               7.2.1
@schematics/update                0.12.1
rxjs                              6.3.3
typescript                        3.2.2
webpack                           4.23.1

2 个答案:

答案 0 :(得分:0)

{     路径:“,     组件:yourComponent   }, 这样通过就可以了

答案 1 :(得分:0)

您的路由中:

const routes: Routes = [
  { path: '', redirectTo: 'home', pathMatch: 'full' },

    {
        "path": "home",
        "component": yourComponent (for example HomeComponent)
  },

并在您的HTML中:

[routerLink]="['/Home']">