0

我正在尝试将路由重定向到某个路径,而它是空的。但在第一种情况下,它获得了正确的路径,但在尝试再次重定向时抛出 404。

在 Breadcrumb 中,当点击 Parent 时,它会正确重定向,路线将是“/parent/child/child1”,在点击 Child 1 时它再次正常工作,但是在点击显示路线时出现“Child”问题“ /parent/child” 只是,但它应该是“/parent/child/child1” 路线,不知道我在这里错过了什么。我试图给它完整的路径(即)但仍然是同样的问题 {path: '', redirectTo: '/parent/child/child1', pathMatch: 'full'},

// App routing module
    export const App_Route: Routes = [
 { path: 'parent',
                data: {pageTitle: 'Parent'},
 loadChildren:'./modules/parent/parent.module#ParentModule'},
]

// Parent module routing

export const Parent_Route: Routes = [
{ path: '', redirectTo: 'child/child1', pathMatch: 'full' },
{
        path: '',
        component: rootWrapper,
        children: [
            {
                path: 'child',
                data: {pageTitle: 'Child Component'},
                loadChildren:'./child/child.module#ChildModule'
            },
]

// Child module routing

export Child_Route: Routes = [
{path: '', redirectTo: 'child1', pathMatch: 'full'},
{
        path: '',
        component: rootWrapper,
        children: [
            {   path: 'child1',
                component: Child1COmponent,
                data: {
                    pageTitle: 'Child 1',
                    authorities: ['ROLE_ADMIN'],
                }]}]

实际:它抛出 404 错误。预期:它应该重定向到 /parent/child/child1

4

1 回答 1

0

尝试在您的路由代码中进行以下给定修改:

export const Parent_Route: Routes = [
    { path: '', redirectTo: 'child/child1', pathMatch: 'full' },
    {
            path: 'child',
            component: rootWrapper,
            children: [
                {
                    path: '',
                    data: {pageTitle: 'Child Component'},
                    loadChildren:'./child/child.module#ChildModule'
                },
    ]

// Child module routing

export Child_Route: Routes = [
{path: '', redirectTo: 'child1', pathMatch: 'full'},
{
        path: 'child1',
        component: rootWrapper,
        children: [
            {   path: '',
                component: Child1COmponent,
                data: {
                    pageTitle: 'Child 1',
                    authorities: ['ROLE_ADMIN'],
                }]}]
于 2019-07-29T05:59:29.153 回答