Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic 4 navigate to tabs

I'm working on an Ionic 4 project, I've generated a tabs project.

What I want to do is create a Login page which is the default page.

When a user has signed in successfully I want to navigate to the tabs.

When I'm trying to do this I get the error:

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

These are my routes:

const routes: Routes = [
  { path: '', loadChildren: './login/login.module#LoginPageModule' },
  { path: 'Login', loadChildren: './login/login.module#LoginPageModule' },
  { path: 'tabs', loadChildren: './tabs/tabs.module#TabsPageModule' },
];

In my Login Page I have a button as follows:

<ion-button expand="block" [href]="'tabs'" color="light" fill="outline">Sign in</ion-button>

When I generate a different page I am able to navigate to this page using the same way.

like image 525
Robin.v Avatar asked Oct 01 '18 09:10

Robin.v


People also ask

How do you use tabs in Ionic 4?

We can access the Ionic tabs by using the standard <ion-tabs> component. This component works as a router outlet to handle navigation. It does not provide any mechanism to switch between tabs. If you need to do switch between tabs, use <ion-tab-bar> as a direct child element of <ion-tabs>.

How do you link tabs in Ionic?

In order to link the ion-tab-button to the ion-tab container, a matching tab property should be set on each component. The ion-tab-button and ion-tab above are linked by the common tab property. The tab property identifies each tab, and it has to be unique within the ion-tabs .

How do I redirect to another page in Ionic?

to​ A redirect route, redirects "from" a URL "to" another URL. This property is that "to" URL. When the defined ion-route-redirect rule matches, the router will redirect to the path specified in this property.


1 Answers

I was facing the same issue. I found a solution here. You need to add an additional route to your routes array.

const routes: Routes = [
  { path: '', loadChildren: './login/login.module#LoginPageModule' },
  { path: 'Login', loadChildren: './login/login.module#LoginPageModule' },
  { path: 'tabs', loadChildren: './tabs/tabs.module#TabsPageModule' },
  { path: '', loadChildren: './tabs/tabs.module#TabsPageModule' },
];
like image 95
Rich Tillis Avatar answered Jan 01 '23 17:01

Rich Tillis