Exploring the transition from a Button component to a Tab within a TabView using NativeScript Angular

In my app.component.html, I have set up a TabView like this:

<TabView androidTabsPosition="bottom">
    <page-router-outlet
        *tabItem="{title: 'Home', iconSource: getIconSource('home')}"
        name="homeTab">
    </page-router-outlet>
    <page-router-outlet
        *tabItem="{title: 'Game', iconSource: getIconSource('browse')}"
        name="gameTab">
    </page-router-outlet>
    <page-router-outlet
        *tabItem="{title: 'Courses', iconSource: getIconSource('search')}"
        name="coursesTab">
    </page-router-outlet>
</TabView>

Additionally, in my app-routing.module.ts file, the routing is set up as follows:

const routes: Routes = [
    {
        path: "",
        redirectTo: "/(homeTab:home/default//gameTab:game/default//coursesTab:courses/default)",
        pathMatch: "full"
    },
    {
        path: "home",
        component: NSEmptyOutletComponent,
        loadChildren: "~/app/home/home.module#HomeModule",
        outlet: "homeTab"
    },
    {
        path: "game",
        component: NSEmptyOutletComponent,
        loadChildren: "~/app/game/game.module#GameModule",
        outlet: "gameTab"
    },
    {
        path: "courses",
        component: NSEmptyOutletComponent,
        loadChildren: "~/app/courses/courses.module#CoursesModule",
        outlet: "coursesTab"
    }
];

@NgModule({
    imports: [NativeScriptRouterModule.forRoot(routes)],
    exports: [NativeScriptRouterModule]
})
export class AppRoutingModule { }

To navigate from the homeTab section by pressing a button in my home.component.html, I write the following code:

<Button text="Add a course" (tap)="gotoCourses()" class="btn-green" width="50%"></Button>

In home.component.ts, I attempt to navigate to the /courses path upon clicking the button using this method:

constructor(private routerExtensions: RouterExtensions) { }

public gotoCourses(){
    this.routerExtensions.navigate(["/courses"]);
}

I have tried various paths for navigation including:

courses
courses/default
//coursesTab
//coursesTab:courses
//coursesTab:courses/default
../coursesTab:courses/default
../coursesTab:courses
../coursesTab
../courses
../courses/default

However, when attempting to navigate, I encounter the error:

Error: Cannot match any routes. URL Segment: 'courses'
Error: Cannot match any routes. URL Segment: 'courses'
    at ApplyRedirects.noMatchError ...

It seems there is an issue with my understanding of navigation within the application. Any assistance would be greatly appreciated in resolving this navigation problem. Although I believe it to be a simple solution, I am unable to determine how to navigate to the "Courses" tab by clicking the button. Navigation through tabs works smoothly. If needed, here is a playground demo link:

Answer №1

When you want to navigate to a new page, use the navigate method. In this particular scenario, the Course is already loaded in the second router outlet on the second tab. Therefore, all you need to do is change the selected index of the tab view.

tabView.selectedIndex = 1; // This will display the course page

Check out the Updated Playground here

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using React TypeScript to trigger a function upon route changes with react-router-dom

I am trying to use the useEffect hook to console log every time the location changes in my project. However, when I try to compile, I receive an error in the terminal saying Unexpected use of 'location' no-restricted-globals. I would like to fin ...

What are effective strategies for troubleshooting Dependency Injection problems in nest.js?

Can someone explain the process of importing a third-party library into NestJS using Dependency Injection? Let's say we have a class called AuthService: export class AuthService { constructor( @Inject(constants.JWT) private jsonWebToken: any, ...

How can I bind the ID property of a child component from a parent component in Angular 2 using @Input?

I have a unique requirement in my parent component where I need to generate a child component with a distinct ID, and then pass this ID into the child component. The purpose of passing the unique ID is for the child component to use it within its template. ...

Electron window widens but does not shrink in size

Currently, I am utilizing electron to create an application where I am using ipc messages to expand and retract the width of the app. The frontend is able to trigger these ipc messages successfully, but for some reason, it refuses to go back to a width of ...

Error with an Array of Objects in an Array when using Angular and Typescript

Our system has an array called "food/essen" with a total of 10 items. The food plan is made up of 8 objects from the "Food" array and includes an ID for the week number. An issue we are facing in our web application is that although it recognizes the 8 o ...

Attaching and detaching dynamic views in Angular within an ngFor loop

I'm currently dealing with an issue where I have a list of chat items that are loaded dynamically. When a user clicks on a specific item, I need to open/close a static component/section (such as a reactions menu) right below that particular chat item. ...

An issue occurred: the channel has been terminated within the ChildProcess.target.send function at internal/child_process.js, line 562, character

My Angular 5 application is giving me an error message that says "ERROR in Error: channel closed". This occurs after running the application. The issue seems to persist even though it works fine for a few minutes after executing ng serve. Has anyone else e ...

Embracing Interfaces Over 'any' Types in TypeScript

https://i.stack.imgur.com/W6NMa.pngWould it be beneficial to utilize an interface as a variable type rather than opting for any? For instance, if I have 3 functions where I am declaring variables that can contain alphanumeric data, would defining them us ...

Unable to determine all parameters for Modal: (?, ?, ?)

import { Component, Inject } from '@angular/core'; import { NavController, Modal } from 'ionic-angular'; import { PopupPage } from '../../components/modal/modal.page'; @Component({ templateUrl: 'build/pages/spot/spot. ...

"Exploring the Power of Angular Change Detection with Promises in a Hybrid

We are currently in the process of upgrading an AngularJS project to Angular 7 by following the recommended "hybrid" approach where both frameworks coexist. However, we have encountered some issues with change detection when dealing with native promises. T ...

How to pass a function parameter as a property in MongoDB and Typescript

I've been working on a project that involves using Mongoose to write, update, and perform other operations in a MongoDB database. Currently, I am utilizing the updateOne() function within my own custom function. However, I am facing an issue where if ...

Encountering difficulties in loading environment variables while starting the server using typescript in combination with node.js

My node.js server project, created using typescript, has the following structure: |--node_modules |--server .env |-- build |-- src |-- database |-- controllers |-- models |-- routes |-- utils |-- app. ...

How to efficiently load a compressed bundle.js file in Angular2 with Webpack?

I recently utilized the Webpack Compression plugin to shrink my bundle.js file and successfully obtained a bundle.js.gz version. However, upon launching the application, I encountered an error: Refused to execute script from 'https://example.com/js/ ...

Angular 2 - Utilizing multiple templates

Recently, I've been working on an application that requires the ability to load different templates dynamically. The standard template structure I'm using is as follows: <!doctype html> <html lang="en"> <head> <meta cha ...

The button with type Submit inside the form is failing to trigger the Form Submit Event

Having an issue with a custom LoadingButton component in my React TypeScript project using Material-UI (MUI) library. The problem occurs when using this LoadingButton within a form with an onSubmit event handler. The LoadingButton has type="submit&quo ...

Is there a way to integrate the pandorabots node module with Nativescript?

I recently came across the Pandorabots API module for Node.js on Github. However, when I tried installing it and running the app, I encountered an error message stating "Could not find module 'fs'". Any help or insight would be much appreciated. ...

How Angular services transmit information to components

I have implemented a search field within my top-bar component and I am facing an issue in passing the input value of that search field to another component. Design Search service Top bar component Result component Operation Top bar component receives th ...

My goal is to link the legend feature with a checkbox that allows the user to toggle the display of the

I am looking to position the legend below the chart (position: left bottom) and bind the legend option with a checkbox to toggle its visibility. How can I achieve this? TypeScript: import { Component } from '@angular/core'; @Component({ se ...

Attempting to convert numerical data into a time format extracted from a database

Struggling with formatting time formats received from a database? Looking to convert two types of data from the database into a visually appealing format on your page? For example, database value 400 should be displayed as 04:00 and 1830 as 18:30. Here&apo ...

Drawing an image on an Ionic 4 canvas using the drawImage method, following a change

I've been working on an app that displays an image on a canvas, with the image source coming from the parent page. Everything seems to be functioning correctly, but when I try changing the imageSrc via a button click, the canvas ends up blank. Oddly ...