【问题标题】:How to return route with a parameter in Angular 7如何在Angular 7中返回带有参数的路由
【发布时间】:2019-07-30 08:03:50
【问题描述】:

我在 Angular 7 中有一个简单的待办事项列表应用程序,我在其中添加了一个在“个人”和“工作”之间切换的按钮。这是切换的功能:

  toggleShowPersonal(){
    if (this.showPersonal){
      this.showPersonal = false; 
    }
    else {
      this.showPersonal = true; 
    }
    this.refreshTodos(); 
  }

一旦列表出现,用户可以选择编辑或添加待办事项。这将通过以下命令将他们带到详细信息页面:

this.router.navigate(['todos',id]);

我正在尝试更改路由命令以添加“showPersonal”参数:

this.router.navigate(['todos',id, this.showPersonal]);

我已更新路由模块以反映更改:

  { path: 'todos/:id,:showPersonal', component: TodoComponent, canActivate:[RouteGuardService]},  

但是,通过此更改,它不再转到详细信息页面,而是默认为登录页面。

我做错了什么?

【问题讨论】:

    标签: angular7 angular7-router


    【解决方案1】:

    参数之间的路径需要/

    path: 'todos/:id/:showPersonal'
    

    【讨论】:

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