【问题标题】:Cannot match any routes angular 2.0.1无法匹配任何路线角度 2.0.1
【发布时间】:2016-11-07 10:14:14
【问题描述】:

我的 plunkr 有问题。 http://plnkr.co/edit/70ZFRPJdAraDDV8heMlo?p=preview

const routes = [
    {path: 'test', component: Test},
    {path: 'home', component: HomeComponent},
    {path: '', redirectTo: 'home', pathMatch: "full"}
];

this.router.navigate('/test');

我不能简单地做一个 router.navigate。我有错误:

错误:无法匹配任何路由。网址段:'t/e/s/t'

在我看来一切都很好。 与Cannot match any routes: '' 相关,但我没有任何子路线。

谢谢

【问题讨论】:

    标签: angular router


    【解决方案1】:

    添加[]

    this.router.navigate(['/test']);
    

    或使用navigateByUrl()

    this.router.navigateByUrl('/test');
    

    Plunker example

    【讨论】:

      【解决方案2】:

      路径和括号前没有斜线...

      this.router.navigate(['test']);
      

      【讨论】:

        猜你喜欢
        • 2021-02-09
        • 2019-06-16
        • 1970-01-01
        • 2020-09-20
        • 1970-01-01
        • 2019-05-11
        • 2018-09-29
        • 2020-06-22
        • 2017-01-21
        相关资源
        最近更新 更多