@Abraham94 wrote:
Hi!
Im trying to navigate from a page to a tab with a button. The problem is that when I try to navigate from the tab to the page, it works, but not in the oposite way. what am I doing wrong?app-routing.module.ts:
import { NgModule } from '@angular/core'; import { PreloadAllModules, RouterModule, Routes } from '@angular/router'; const routes: Routes = [ { path: '', loadChildren: () => import('./login/login.module').then( m => m.LoginPageModule) }, { path: 'tabs', loadChildren: () => import('./tabs/tabs.module').then(m => m.TabsPageModule) } ]; @NgModule({ imports: [ RouterModule.forRoot(routes, { preloadingStrategy: PreloadAllModules }) ], exports: [RouterModule] }) export class AppRoutingModule { }
tabs-routing.module.ts:
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: 'tab1', loadChildren: () => import('../tab1/tab1.module').then(m => m.Tab1PageModule) }, { path: 'tab2', loadChildren: () => import('../tab2/tab2.module').then(m => m.Tab2PageModule) }, ] }, { path:'', redirectTo:'/tabs/tab1', pathMatch:'full' } ]; @NgModule({ imports: [RouterModule.forChild(routes)], exports: [RouterModule], }) export class TabsPageRoutingModule {}
method to navigate from page to tab:
import { Component, OnInit } from ‘@angular/core’;
import { Router } from ‘@angular/router’;@Component({
selector: ‘app-login’,
templateUrl: ‘./login.page.html’,
styleUrls: [’./login.page.scss’],
})
export class LoginPage implements OnInit {constructor(private router : Router) { }
ngOnInit() {
}checkLogin(){
console.log(“HOLIII”)
console.log(this.router.navigate([‘tabs/tab1’]))
}}
If u need more info , let me know.
Thanks!
Posts: 1
Participants: 1