Ionic Tabs with Url Parameter

Viewed 84

I am using tabs where the parent of the url is :username I think this is where my issue is stemming from. When I go to the tabs page it won't load the default tab. When I navigate to localhost:3000/REAL-USERNAME/tabs I get:

ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'tabs/account'
Error: Cannot match any routes. URL Segment: 'tabs/account'

What I am doing for the moment is linking 'tabs/account' via the [routerLink]="['/', currentUser, 'tabs', 'account']" in the template html file but that is not a best practice or future proof from my perspective.

I'm sure I am missing something simple. Any help would be appreciated. Let me know if you need to see more code.


tabs.page.html:

<ion-tabs>
  <ion-tab-bar slot="bottom">
    <ion-tab-button tab="account">
      <ion-icon name="person-circle-outline"></ion-icon>
      <ion-label>Account</ion-label>
    </ion-tab-button>

    <ion-tab-button tab="preferences">
      <ion-icon name="finger-print-outline"></ion-icon>
      <ion-label>Preferences</ion-label>
    </ion-tab-button>

    <ion-tab-button tab="blocks">
      <ion-icon name="ban-outline"></ion-icon>
      <ion-label>Blocks</ion-label>
    </ion-tab-button>
  </ion-tab-bar>
</ion-tabs>


tabs-routing.module.ts:

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

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


const routes: Routes = [
  {
    path: '',
    component: TabsPage,
    children: [
      {
        path: 'account',
        children: [{
          path: '',
          loadChildren: () => import('./user/user.module').then( m => m.UserPageModule),
        }]
      },
      {
        path: 'preferences',
        children: [{
          path: '',
          loadChildren: () => import('./preferences/preferences.module').then( m => m.PreferencesPageModule),
        }]
      },
      {
        path: 'blocks',
        children: [{
          path: '',
          loadChildren: () => import('./blocks/blocks.module').then( m => m.BlocksPageModule),
        }]
      },
      {
        path: '',
        redirectTo: '/tabs/account',
        pathMatch: 'full'
      }
    ]
  },
  {
    path: '',
    redirectTo: '/tabs/account',
    pathMatch: 'full'
  }
];

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

app-routing.module.ts:

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

const routes: Routes = [
  {
    path: '',
    loadChildren: () => import('./pages/home/home.module').then( m => m.HomePageModule),
  },
  {
    path: ':username',
    loadChildren: () => import('./pages/profile/profile.module').then( m => m.ProfilePageModule),
  },
  {
    path: ':username/tabs',
    loadChildren: () => import('./pages/profile/tabs/tabs.module').then( m => m.SettingsPageModule),
  },
  

];

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

0 Answers
Related