Error: Cannot match any routes. URL Segment: 'tabs'

Error: Cannot match any routes. URL Segment: 'tabs'

我正在尝试为我的 ionic 4 应用创建标签页布局。在我的配置和设置之后,我收到错误错误:无法匹配任何路由。 URL 段:'tabs'

首先,当我使用选项卡模板创建默认启动器时,它不起作用。选项卡栏显示但不显示选项卡内容。经过几天的研究和测试,还没有运气。看看我现在有什么;

我的 Ionic 信息

Ionic:
   ionic (Ionic CLI)             : 4.6.0 (C:\Users\Ken\AppData\Roaming\npm\node_modules\ionic)
   Ionic Framework               : @ionic/angular 4.0.0-beta.17
   @angular-devkit/build-angular : 0.10.7
   @angular-devkit/schematics    : 7.0.7
   @angular/cli                  : 7.0.7
   @ionic/angular-toolkit        : 1.2.0

System:

   NodeJS : v10.13.0 (C:\Program Files\nodejs\node.exe)
   npm    : 6.4.1
   OS     : Windows 10

应用-routing.module.ts

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';

const routes: Routes = [
  {
    path: '',
    redirectTo: 'home',
    pathMatch: 'full'
  },
  {
    path: 'home',
    loadChildren: './home/home.module#HomePageModule'
  },
  { path: 'tabs', loadChildren: './tabs/tabs.module#TabsPageModule' }
];

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

tabs.router.module.ts

import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';

import { TabsPage } from './tabs.page';


const routes: Routes = [
  {
      path: 'tabs',
      component: TabsPage,
      children: [
          {
              path: 'tab1',
              outlet: 'tab1',
              loadChildren: '../tab1/tab1.module#Tab1PageModule'
          },
          {
              path: 'tab2',
              outlet: 'tab3',
              loadChildren: '../tab2/tab2.module#Tab2PageModule'
          },
          {
              path: 'tab3',
              outlet: 'tab3',
              loadChildren: '../tab3/tab3.module#Tab3PageModule'
          }
      ]
  },
  {
      path: '',
      redirectTo: '/tabs/(one:one)'
  }
];


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

tabs.page.html

<ion-tabs>

  <!-- Tabs -->
  <ion-tab tab="tab1">
    <ion-router-outlet name="tab1"></ion-router-outlet>
  </ion-tab>

  <ion-tab tab="tab2">
    <ion-router-outlet name="tab2"></ion-router-outlet>
  </ion-tab>

  <ion-tab tab="tab3">
    <ion-router-outlet name="tab3"></ion-router-outlet>
  </ion-tab>

  <!-- Tab Buttons -->
  <ion-tab-bar slot="bottom">

    <ion-tab-button tab="tab1" href="/tabs/(tab1:tab1)">
      <ion-icon name="navigate"></ion-icon>
      <ion-label>tab1</ion-label>
    </ion-tab-button>

    <ion-tab-button tab="tab2" href="/tabs/(tab2:tab2)">
      <ion-icon name="person"></ion-icon>
      <ion-label>tab2</ion-label>
    </ion-tab-button>

    <ion-tab-button tab="tab3" href="/tabs/(tab3:tab3)">
      <ion-icon name="bookmarks"></ion-icon>
      <ion-label>tab3</ion-label>
    </ion-tab-button>

  </ion-tab-bar>

</ion-tabs>

我预计当我导航到 /tabs 时默认加载 tab1 的内容,然后单击 tab2 图标应该同样在 tab2page 等上显示内容。但是当我做 ionic serve 时出现上面的错误然后将 /tabs 添加到 url。这里的任何帮助将不胜感激。感谢期待。

好吧,我必须更新环境,然后使用重大更改指南让我的标签页正常工作。以下资源非常有用:

https://forum.ionicframework.com/t/how-to-update-ionic-4-project-to-latest-beta-release/140050/2 https://github.com/ionic-team/ionic/blob/master/CHANGELOG.md#angular-tabs

现在我的 Ionic 信息如下所示:

Ionic:

   ionic (Ionic CLI)             : 4.6.0 (C:\Users\Ken\AppData\Roaming\npm\node_modules\ionic)
   Ionic Framework               : @ionic/angular 4.0.0-rc.0
   @angular-devkit/build-angular : 0.11.4
   @angular-devkit/schematics    : 7.1.4
   @angular/cli                  : 7.1.4
   @ionic/angular-toolkit        : 1.2.2

System:

   NodeJS : v10.13.0 (C:\Program Files\nodejs\node.exe)
   npm    : 6.4.1
   OS     : Windows 10

我的 package.json 看起来像这样:

 "dependencies": {
    "@angular/common": "~7.1.4",
    "@angular/core": "~7.1.4",
    "@angular/forms": "~7.1.4",
    "@angular/http": "~7.1.4",
    "@angular/platform-browser": "~7.1.4",
    "@angular/platform-browser-dynamic": "~7.1.4",
    "@angular/router": "~7.1.4",
    "@ionic-native/core": "5.0.0-beta.21",
    "@ionic-native/splash-screen": "5.0.0-beta.21",
    "@ionic-native/status-bar": "5.0.0-beta.21",
    "@ionic/angular": "4.0.0-rc.0",
    "core-js": "^2.5.4",
    "rxjs": "~6.3.3",
    "zone.js": "~0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/architect": "~0.11.4",
    "@angular-devkit/build-angular": "~0.11.4",
    "@angular-devkit/core": "~7.1.4",
    "@angular-devkit/schematics": "~7.1.4",
    "@angular/cli": "~7.1.4",
    "@angular/compiler": "~7.1.4",
    "@angular/compiler-cli": "~7.1.4",
    "@angular/language-service": "~7.1.4",
    "@ionic/angular-toolkit": "~1.2.0",
    "@types/jasmine": "~2.8.8",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~10.12.0",
    "codelyzer": "~4.5.0",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~3.1.4",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.12.0",
    "typescript": "3.1.6"
  }

现在,官方 Ionic 4 文档中的示例 https://beta.ionicframework.com/ 可以按预期工作。

替换 tabs.router.module.ts

中的这些行
{
      path: '',
      redirectTo: '/tabs/tabs/(one:one)'
  }

您必须在最终重定向之前添加“/tabs”。

在tabs.router.module.ts

删除路径:'tabs' under routes:Routes 那么代码将是这样的。我正在粘贴我文件中的代码

const routes: Routes = [   {
    path: '',
    component: TabsPage,
    children: [
      {
        path: 'tab1',
        loadChildren: () => import('../tab1/tab1.module').then(m => m.Tab1PageModule)
      },
      {
        path: 'tab2',
        loadChildren: () => import('../tab2/tab2.module').then(m => m.Tab2PageModule)
      },
      {
        path: 'tab3',
        loadChildren: () => import('../tab3/tab3.module').then(m => m.Tab3PageModule)
      },
      {
        path: '',
        redirectTo: '/tabs/tab1',
        pathMatch: 'full'
      }
    ]   }, ];

在应用程序中-routing.module.ts代码将是这样的

const routes: Routes = [    {
    path: 'login',
    loadChildren: () => import('./login/login.module').then( m => m.LoginPageModule)   },   {
    path: 'tabs',
    loadChildren: () => import('./tabs/tabs.module').then(m => m.TabsPageModule)   },      {
    path : '',
    redirectTo : 'login',
    pathMatch : 'full'   } ];