【问题标题】:A route with parameters in Angular outputs 404Angular 中带有参数的路由输出 404
【发布时间】:2022-10-21 15:25:03
【问题描述】:

Angular 13 上的项目。

路线说明

const routes: Routes = [
  {
    path: '',
    component: DefaultLayoutComponent,
    children: [
      {
        path: 'my-path/:my-param',
        component: MyComponent
      }
    ]
  }
];

这是过渡到它

this.router.navigate(['my-path'], { queryParams: { my-param: 'value' } });

结果,我在第 404 页被抛出。

我的错误在哪里?

【问题讨论】:

  • 试试这个:this.router.navigate(['my-path', 'value']);。根据您在帖子中的代码,queryParams 不适用。
  • 它也不是那样工作的。为什么我不能使用 queryParams。我怎么了?
  • 那么它实际上导航到哪里呢?您的控制台中有任何错误吗?

标签: angular angular-routing


【解决方案1】:

你可以检查你的 index.html 文件是否有一个基本标签添加到头部。

<base href="/">

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-07-14
    • 1970-01-01
    • 2018-03-08
    • 2017-08-31
    • 2019-06-01
    • 2021-12-01
    • 1970-01-01
    • 2019-11-15
    相关资源
    最近更新 更多