首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Ionic 4:重定向到带有id参数的路由

Ionic 4:重定向到带有id参数的路由
EN

Stack Overflow用户
提问于 2019-03-24 23:29:07
回答 2查看 1.4K关注 0票数 1

假设在我们的英雄angular 7/ionic 4英雄应用程序中,我们有一个带有两个标签的HeroDetailsRoutingModule,即SuperpowersPageCostumePage

现在,我们希望将SuperpowersPage定义为default选项卡。

所以我试着设置我的HeroDetailsRoutingModule:

代码语言:javascript
复制
const routes: Routes = [
    {
        path: 'tabs/',
        component: HeroDetailsPage,
        children: [
            {
                path: 'superpowers',
                loadChildren: './superpowers/superpowers.module#SuperpowersPageModule'
            },
            {
                path: 'costume',
                loadChildren: './costume/costume.module#CostumePage'
            },
            {
                path: '',
                redirectTo: '/heroes/:heroId/tabs/superpowers',
                pathMatch: 'full'
            }
        ]
    },
    {
        path: '',
        redirectTo: '/heroes/:heroId/tabs',
        pathMatch: 'full'
    }
];

当然,这不起作用,因为我们在此模块中没有:heroId。在这种情况下,重定向的正确方式是什么?我尝试使用相对路径(例如redirectTo: './tabs/superpowers'),但也不起作用。我有感觉犯了一些明显的错误,但我不明白。提前感谢!

EN

回答 2

Stack Overflow用户

发布于 2019-05-13 19:23:43

我用这种方法解决了这个问题

在HeroDetailsRoutingModule中将路由定义为

代码语言:javascript
复制
 const routes: Routes = [
    {
        path: 'tabs',
        component: HeroDetailsPage,
        children: [
            {
                path: 'superpowers',
                children:[
                 { path : ':heroId',
                  loadChildren: './superpowers/superpowers.module#SuperpowersPageModule'
                 }
                ]
            },
            {
                path: 'costume',
                loadChildren: './costume/costume.module#CostumePage'
            }
        ]
    },
    {
        path: '',
        redirectTo: 'tabs/superpowers',
        pathMatch: 'full'
    }
];

在hero-details.page.ts中设置heroId的值

代码语言:javascript
复制
heroId =  <value>// get the value of heroId 

然后在hero-details.page.html文件访问选项卡中

代码语言:javascript
复制
<ion-tab-button tab="superpowers/{{heroId}}">
票数 1
EN

Stack Overflow用户

发布于 2019-03-25 00:14:52

我认为如果你通过:希罗德到路径‘超能力’,它应该可以工作。当你尝试这个的时候会发生什么.

代码语言:javascript
复制
const routes: Routes = [
    {
        path: 'tabs/',
        component: HeroDetailsPage,
        children: [
            {
                path: 'superpowers/:heroId',
                loadChildren: './superpowers/superpowers.module#SuperpowersPageModule'
            },
            {
                path: 'costume',
                loadChildren: './costume/costume.module#CostumePage'
            },
            {
                path: '',
                redirectTo: '/heroes/:heroId/tabs/superpowers',
                pathMatch: 'full'
            }
        ]
    },
    {
        path: '',
        redirectTo: '/heroes/:heroId/tabs',
        pathMatch: 'full'
    }
];
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55325378

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档