路由器导航不会重定向到其他页面 [英] router navigate doesn't redirect to other page
问题描述
当用户单击数据表行时,我会将其重定向到另一个页面
在 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屋!