1

I am creating an app starting from the NativeScript TabView template app (https://github.com/NativeScript/template-tab-navigation-ng), and I can't figure out how to programmatically navigate to a page within a page-router-outlet from AppComponent. Example:

export class AppComponent{

    constructor(private router: RouterExtensions, private currentRoute: ActivatedRoute) {
        // Use the component constructor to inject providers.
    }

    getIconSource(icon: string): string {
        const iconPrefix = isAndroid ? "res://" : "res://tabIcons/";
        return iconPrefix + icon;
    }

    navigateToPage(): void {
        this.router.navigate(['../page'], { relativeTo: this.currentRoute });
    }
}

This works fine from within a page inside the page-router-outlet, but when I call it from AppComponent, I get a console error such as this:

Cannot match any routes. URL Segment: 'page'

My actual code is here: https://github.com/rchisholm/saint_stan

My actual full error is here, from the debugging console:

Unhandled Promise rejection: Cannot match any routes. URL Segment: 'novena-day/1' ; Zone: <root> ; Task: Promise.then ; Value: Error: Cannot match any routes. URL Segment: 'novena-day/1' Error: Cannot match any routes. URL Segment: 'novena-day/1'

My attempted navigation is inside of a LocalNotifications.addOnMessageReceivedCallback in OnInit in AppComponent.

This seems like it should be simple. I am a bit new at this, so any help would be greatly appreciated.

I am using the latest versions of NativeScript, TypeScript, and Angular.

Thanks!

1 Answer 1

4

This is how you navigate to some TabView tab. Your outlets have to be set in app.routing.ts file.

private navigateToFoo() {
    this.routerExtensions.navigate([
        '/YourTabRouting', { outlets: { fooOutlet: ['foo'] } }
    ])
}
Sign up to request clarification or add additional context in comments.

4 Comments

How do i set up outlets in app-routing.module.ts? My paths are set up like this: { path: "pageOne", component: PageOneComponent, outlet: "tabOne" }
("pageOne" being a page within my outlet "tabOne")
Thanks for your answer @mrisek, your answer was very helpful.
Thanks @RussellChisholm, don't forget to upwote the answer if you find it useful.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.