路由器导航不会重定向到其他页面 [英] router navigate doesn't redirect to other page

查看:84
本文介绍了路由器导航不会重定向到其他页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户单击数据表行时,我会将其重定向到另一个页面

HTML

 < p表[value] ="users" selectionMode ="single" [[selection]] ="selectedUser" dataKey ="uid"(onRowSelect)="selectedUserDetails($ event)" styleClass =制表结果"> 

在TS文件中

  selectedUserDetails(userDetails){console.log(userDetails);console.log("enterhere");//打印在控制台dev上this.router.navigate ['/userdetails'];} 

模块路由

  const路由:路由= [{小路: "",组件:AdministrationComponent,孩子们: [{path:",component:ResulTabComponent,pathMatch:"full"},{路径:"userdetails",组件:UserDisplayComponent}]}]; 

对于信息管理路径,此路径上是延迟加载的 http://localhost:4200/administration

用户详细信息应为 http://localhost:4200/administration/userdetails

管理组件

 < router-outlet></router-outlet> 

我的问题是,单击时我不会重定向到 userdetails 页面,但是当我从网址栏中导航到/userdails时,我会看到该组件

解决方案

您尚未调用该函数,只是尝试在 navigate

中访问名称为/userdetails 的属性代码>属性.您错过了()

  this.router.navigate(['/userdetails']);^^ 

I would redirect user to another page when he clicks on a datatable row

In HTML

<p-table  [value]="users" selectionMode="single"  [(selection)]="selectedUser" dataKey="uid" (onRowSelect)="selectedUserDetails($event)" styleClass="tab-result">

in TS file

selectedUserDetails(userDetails) {
   console.log(userDetails);
   console.log("enterhere"); // is printed on console dev
   this.router.navigate['/userdetails'];
}

In module routing

const routes: Routes = [
  {
    path: "",
    component: AdministrationComponent,
    children: [
      { path: "", component: ResulTabComponent, pathMatch: "full" },
      { path: "userdetails", component: UserDisplayComponent }
    ]
  }
];

For information administration route is lazy loaded on this path http://localhost:4200/administration

userdetails should be http://localhost:4200/administration/userdetails

In administration component

<router-outlet></router-outlet>

My problem is that when clicking I don't get redirected to the userdetails page but when I navigate to /userdails from url bar I see the component

解决方案

You have not called the function, you just try to access a property with name /userdetails in the navigate property. You missed ()

this.router.navigate(['/userdetails']);
                    ^                ^

这篇关于路由器导航不会重定向到其他页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆