路由器导航不会重定向到其他页面 [英] router navigate doesn't redirect to other page
问题描述
当用户点击数据表行时,我会将用户重定向到另一个页面
I would redirect user to another page when he clicks on a datatable row
在HTML
<p-table [value]="users" selectionMode="single" [(selection)]="selectedUser" dataKey="uid" (onRowSelect)="selectedUserDetails($event)" styleClass="tab-result">
在 TS 文件中
selectedUserDetails(userDetails) {
console.log(userDetails);
console.log("enterhere"); // is printed on console dev
this.router.navigate['/userdetails'];
}
在模块路由
const routes: Routes = [
{
path: "",
component: AdministrationComponent,
children: [
{ path: "", component: ResulTabComponent, pathMatch: "full" },
{ path: "userdetails", component: UserDisplayComponent }
]
}
];
信息管理路由在此路径上延迟加载http://localhost:4200/administration
For information administration route is lazy loaded on this path http://localhost:4200/administration
userdetails 应该是 http://localhost:4200/administration/userdetails
userdetails should be http://localhost:4200/administration/userdetails
在管理组件
<router-outlet></router-outlet>
我的问题是,单击时我没有被重定向到 userdetails
页面,但是当我从 url 栏导航到/userdails 时,我看到了组件
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
推荐答案
您还没有调用该函数,您只是尝试访问 navigate
中名为 /userdetails
的属性代码>属性.你错过了()
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屋!