I have everything properly configured in my routes and no errors are popping up. When the initial tab is loaded, I am attempting to automatically switch to the second tab based on whether the user is logged in or not.
tabs-routing.module.ts file:
import { NgModule } from "@angular/core";
import { Routes } from "@angular/router";
import { NativeScriptRouterModule } from "nativescript-angular/router";
import { TabsComponent } from "./tabs.component";
import { AccountComponent } from './account/account.component';
import { AuthComponent } from './account/auth/auth.component';
import { AddComponent } from './add/add.component';
import { PantryComponent } from './pantry/pantry.component';
const routes: Routes = [
{ path: "", component: TabsComponent, children: [
{path: 'pantry', component: PantryComponent},
{path: 'add', component: AddComponent},
{path: 'account', component: AccountComponent, children: [
{path: 'auth', component: AuthComponent}
]}
]},
];
@NgModule({
imports: [NativeScriptRouterModule.forChild(routes)],
exports: [NativeScriptRouterModule]
})
export class TabsRoutingModule { }
pantry.component.ts file:
import { Component, OnInit } from "@angular/core";
import { Router } from "@angular/router";
import { NativeScriptRouterModule } from "nativescript-angular/router";
require( "nativescript-localstorage" );
@Component({
selector: "pantry",
moduleId: module.id,
templateUrl: "./pantry.component.html"
})
export class PantryComponent implements OnInit {
constructor(private router : Router, private realRouter: NativeScriptRouterModule) {
/* ***********************************************************
* Use the constructor to inject services.
*************************************************************/
}
ngOnInit(): void {
/* ***********************************************************
* Use the "ngOnInit" handler to initialize data for the view.
*************************************************************/
var loggedIn = sessionStorage.getItem('loggedIn');
if(loggedIn == 'true'){
console.log(loggedIn);
}
else{
console.log(loggedIn);
this.router.navigate(['/tabs/add']);
}
}
}
this seems ineffective. What could be preventing navigation to the AddComponent?