在我的Nativescript / Angular应用程序中,我有一个名为UsersModule的主模块;它包含两个模块,UsersListModule和ManageUserModule。结构如下: -用户
- users
- manageUsers
* manageUsers-routing.module.ts
* manageUsers.component.ts
* manageUsers.component.html
* manageUsers.module.ts
- usersList
* usersList-routing.module.ts
* usersList.component.ts
* usersList.component.html
* usersList.module.ts
* users-routing.module.ts
* users-routing.module.html
* users.component.ts
* users.module.ts
这是应用程序的路由:
const routes: Routes = [
{ path: "", redirectTo: "/login", pathMatch: "full" },
{ path: "login", component: LoginComponent },
{ path: "users", loadChildren: "~/app/users/users.module#UsersModule", canActivate: [AuthGuard] }
];
这是UsersRoutingModule:
const routes: Routes = [
{
path: "default", component: UsersComponent, canActivate: [AuthGuard], children: [
{ path: "usersList", component: NSEmptyOutletComponent, loadChildren: "~/app/users/usersList/usersList.module#UsersListModule", outlet: "usersList" },
{ path: "manageUsers", component: NSEmptyOutletComponent, loadChildren: "~/app/users/manageUsers/manageUsers.module#ManageUsersModule", outlet: "manageUsers" },
]
}
];
这是UsersList路由:
const routes: Routes = [
{ path: "", redirectTo: "usersList" },
{ path: "usersList", component: UsersListComponent }
];
这是MangeUsers的路由:
const routes: Routes = [
{ path: "", redirectTo: "newUser" },
{ path: 'newUser', component: ManageUserComponent },
{ path: 'editUser/:userId', component: ManageUserComponent }
];
这是users.component.html:
.....
<page-router-outlet name="usersList"></page-router-outlet>
<page-router-outlet name="manageUsers"></page-router-outlet>
.....
问题是当我在用户列表中并且我想编辑所选的用户时,angular无法找到细分网址,也无法重定向我。在UsersListComponent中,我具有以下功能:
goToEdit(data) {
let urlTree = this.router.createUrlTree(['../editUser', data.userId], {
relativeTo: this.activeRoute
});
this.routerExtensions.navigateByUrl(urlTree);
};
但是如果我尝试编辑它,则会返回此错误:
错误错误:未捕获(承诺):错误:无法匹配任何路由。网址段:“用户/默认”
在users.component的sidenav中,我尝试执行以下操作:
open() {
this.closeSideDrawer();
const urlTree = this.router.createUrlTree(['/users/newUser'], {
relativeTo: this.activeRoute
});
this.routerExtensions.navigateByUrl(urlTree);
}
但是,如果我单击,它不会重定向,只会关闭侧边栏,什么也不会发生