首页 > 解决方案 > Ionic 4/5 - 错误:路由:当标签页用作组件时

问题描述

大家好,当我使用 Tabs 作为组件时,我遇到了路由问题。

我所做的是,我制作了一个标签页和一个 shared.Module.Ts 文件。

在 shared.Module.Ts 文件中,我导入标签页,因为我想在许多页面中使用此标签。Tabs 页面在其他页面中完全导入成功,但我卡在 Routing 中,它给了我一个错误

ERROR 错误:未捕获(在承诺中):错误:无法匹配任何路由。URL 段:“家庭/地址”

请帮帮我这是我的代码

Shared.module.ts 文件


import { NgModule } from "@angular/core";
import { CommonModule } from "@angular/common";
import { TabsPage } from "../pages/tabs/tabs.page";

@NgModule({
    declarations: [TabsPage],
    exports: [TabsPage],
    imports: [CommonModule],
})
export class SharedModule {}


标签页


<ion-tab-bar slot="bottom">
  <ion-tab-button tab="home">
    <ion-icon name="triangle"></ion-icon>
    <ion-label>Tab 1</ion-label>
  </ion-tab-button>

  <ion-tab-button tab="myaccount">
    <ion-icon name="ellipse"></ion-icon>
    <ion-label>Tab 2</ion-label>
  </ion-tab-button>

  <ion-tab-button tab="address">
    <ion-icon name="square"></ion-icon>
    <ion-label>Tab 3</ion-label>
  </ion-tab-button>
</ion-tab-bar>

选项卡路由.module.ts

    import { NgModule } from "@angular/core";
import { RouterModule, Routes } from "@angular/router";
import { AddressPage } from "../address/address.page";
import { HomePage } from "../home/home.page";
import { MyaccountPage } from "../myaccount/myaccount.page";
import { TabsPage } from "./tabs.page";

const routes: Routes = [
    {
        path: "tabs",
        component: TabsPage,
        children: [
            {
                path: "home",
                children: [
                    {
                        path: "",
                        component: HomePage,
                    },
                ],
            },
            {
                path: "myaccount",
                children: [
                    {
                        path: "",
                        component: MyaccountPage,
                    },
                ],
            },
            {
                path: "wallet",
                children: [
                    {
                        path: "",
                        component: AddressPage,
                    },
                ],
            },
            {
                path: "",
                redirectTo: "/tabs/home",
                pathMatch: "full",
            },
        ],
    },
    {
        path: "",
        redirectTo: "/tabs/home",
        pathMatch: "full",
    },
];

@NgModule({
    imports: [RouterModule.forChild(routes)],
    exports: [RouterModule],
    })
export class TabsPageRoutingModule {}

请帮我。谢谢

标签: angulartypescriptionic-frameworkionic4

解决方案


推荐阅读