Search code examples
ionic-frameworkionic4routerlinkionic-tabs

Ionic: routerLink does not work anymore since implementing navigation using tabs


Ever since I implemented the tab bar I am no longer able to navigate without using the tab bar. There is some navigation that I'd like to do outside of the tab bar.

TAB BAR

<ion-tabs>

  <ion-tab-bar slot="bottom">
    <ion-tab-button tab="map">
      <ion-icon name="map-outline"></ion-icon>
      <ion-label>Map</ion-label>
    </ion-tab-button>

    <ion-tab-button tab="restaurant-list">
      <ion-icon name="storefront-outline"></ion-icon>
      <ion-label>Restaurants</ion-label>
    </ion-tab-button>
  </ion-tab-bar>

</ion-tabs>

TAB ROUTING

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

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

const routes: Routes = [
  {
    path: 'tabs',
    component: TabsPage,
    children: [
      {
        path: 'map',
        loadChildren: () => import('../map/map.module').then(m => m.MapPageModule)
      },
      {
        path: 'item-details',
        loadChildren: () => import('../item-details/item-details.module').then(m => m.ItemDetailsPageModule)
      },
      {
        path: 'restaurant-list',
        loadChildren: () => import('../restaurant-list/restaurant-list.module').then(m => m.RestaurantListPageModule)
      },

      {
        path: 'restaurant-details',
        loadChildren: () => import('../restaurant-details/restaurant-details.module').then(m => m.RestaurantDetailsPageModule)
      },
      {
        path: 'item-details',
        loadChildren: () => import('../item-details/item-details.module').then(m => m.ItemDetailsPageModule)
      },
    ]
  },
  {
    path: '',
    redirectTo: 'tabs/map',
    pathMatch: 'full'
  }
];

I CAN NOT LONGER NAVIGATE USING

<a routerLink='/restaurant-list'>Continue to view restaurants</a>

I'VE ALSO TRIED BUT I AM STILL UNSUCESSFUL

<a routerLink='/tabs/restaurant-list'>Continue to view restaurants</a>

Solution

  • The issue was that I had a modal over the page I was navigating from so when I navigated, the modal was still on top of the new page. I was using Ionic Lab so I was unaware that the navigation was actually working until I did a regular ionic serve. I have since dismissed the modal at the correct point and all is well.

    This is the correct way to use routerLink btw

    <a routerLink='/tabs/restaurant-list' >Continue to view restaurants</a>