Issues may arise when attempting to navigate within a lazy module using Angular Nativescript

Recently, I utilized a template called Nativescript-Tabs-Template from this GitHub repository.

While attempting to navigate to a sibling component (both within the same lazy module), I encountered the following issue:

 showItem() {
    this.routerExtensions.navigate(["details/"]);
}

(I also tried the following method - not entirely certain if it is correct) :

this.routerExtensions.navigate(["details", { outlets: { searchTab: ['details'] } }]);

The error message received was:

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

However, when using nsRouterLink for navigation, it works successfully:

<Label text="this works" [nsRouterLink]="['/details']></Label>

Within App.components.html's Tab section:

<TabView androidTabsPosition="bottom">
    <page-router-outlet
    *tabItem="{title: 'Search', iconSource: getIconSource('search')}"
    name="searchTab">
    </page-router-outlet>
</TabView>

In Router.module.ts:

const routes: Routes = [
{
    path: "",
    redirectTo: "/(homeTab:home/default//browseTab:browse/default//searchTab:search/default)",
    pathMatch: "full"
},
    {
        path: "search",
        component: NSEmptyOutletComponent,
        loadChildren: "~/app/search/search.module#SearchModule",
        outlet: "searchTab"
    }
]

For Search.module.ts:

import { NgModule, NO_ERRORS_SCHEMA } from "@angular/core";
import { NativeScriptCommonModule } from "nativescript-angular/common";

import { SearchRoutingModule } from "./search-routing.module";
import { SearchComponent } from "./search.component";
import { NgShadowModule } from 'nativescript-ng-shadow';
import { NativeScriptFormsModule } from "nativescript-angular/forms";
import { LabelMaxLinesDirective } from "../directives/label-max-lines.directive";
import { ItemDetailComponent } from "./item-detail/item-detail.component";

@NgModule({
    imports: [
        NativeScriptCommonModule,
        SearchRoutingModule,
        NgShadowModule,
        NativeScriptFormsModule,
    ],
    declarations: [
        SearchComponent,
        LabelMaxLinesDirective,
        ItemDetailComponent
    ],
    schemas: [
        NO_ERRORS_SCHEMA
    ]
})
export class SearchModule { }

And in Search.router.module.ts:

import { NgModule } from "@angular/core";
import { Routes } from "@angular/router";
import { NativeScriptRouterModule } from "nativescript-angular/router";

import { SearchComponent } from "./search.component";
import { ItemDetailComponent } from "./item-detail/item-detail.component";

const routes: Routes = [
    { path: "default", component: SearchComponent },
    { path: "details", component: ItemDetailComponent }
];

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

Any insights on what might be going wrong in my implementation?

Answer №1

Did you give this a shot?

this.routerExtensions.navigate(["/search/details"]);
Make sure to include the parent route path before its child path.

Answer №2

It is advised not to use the NativeScript Tabs Template anymore. Instead, refer to this tutorial from the official NativeScript Blog:

You can also check out the example on GitHub:

https://github.com/NativeScript/login-tab-navigation-ng

This particular example showcases each tab having its own navigation tree, allowing independent back and forward movements (similar to how the Facebook app operates). Within the tabs, all navigation is relative, so avoid using something like ['/foo'].

constructor(
  private route: ActivatedRoute,
  private router: RouterExtensions
) { }

goForward() {
  const navigation: ExtendedNavigationExtras = {
    relativeTo: this.route,
    transition: {
    name: 'slide'
    }
  };

  this.router.navigate(['../foo'], navigation);
}

goBack() {
  this.router.back();
}

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

What is the best way to update the button color in Angular's latest MDC (16+) version?

After transitioning to MDC-based Angular Material Components, I encountered an issue where the classes in my Angular components were no longer able to override the color of a material button. If you'd like to see a live example of this problem, click ...

What is the best way to change a number into a byte string using TypeScript?

If I have a number represented by 3 bytes in hexadecimal form as 0x303132, how can I transform this number into a string of three characters with the same value - '012' - where each character represents the ASCII value of the corresponding byte? ...

Ways to modify styles defined in the global style.scss file using a child component's CSS and constraining it to affect only that specific component

When working on my Angular project, I have implemented some CSS styling in the global style.css file located at src/style.css. However, there are instances where I need to modify certain styles within a specific component only. Currently, I am able to achi ...

When a Vue3/Vuex object created using reactive() is used as a payload in a mutation to Vuex, it loses its reactivity

Ever wondered why you might need a reactive object compatible with Provide/Inject for your Vuex Store? Well, it's all about flexibility and functionality! Picture this: you have a plugin for authentication that needs to be integrated into your app. B ...

Prevent data loss on webpage refresh by using Angular's local storage feature

As a beginner in Angular, I am exploring ways to retain user input and interactions on my webpage even after a refresh. After some research, I came across using local storage as a viable solution. A different answer suggested utilizing the following code s ...

Querying specific documents with Angular Firebase reference is a breeze

I'm currently encountering an issue when attempting to query documents in one collection with a reference to another document in a separate collection. Here is the scenario I am dealing with: There are two collections: "posts" and "users". Every "pos ...

Having trouble with importing files from a different folder in a React Typescript project

I have a specific folder arrangement set up https://i.sstatic.net/GFOYv.png My goal is to bring both MessageList.tsx and MessageSent.tsx into my Chat.tsx file // Chat.tsx import React from 'react' import {MessageList, MessageSent} from "./ ...

Tips for waiting for an Http response in TypeScript with Angular 5

Is it possible to create a function that can retrieve a token from a server, considering that the http.post() method generates a response after the function has already returned the token? How can I ensure that my function waits for the http.post() call t ...

Can a directive selector include the colon symbol?

Can a colon symbol be included in a directive selector? It seems to be causing an issue @Directive({ selector: '[my:selector]' }) class MyDirective { constructor(el: ElementRef) {} } view plunker ...

JSON definitions for Google Apps Scripts in TypeScript

Is there a way to obtain Typescript definitions for the raw JSON schema when creating a Google App Script with a cloud function, as outlined in the following link: https://developers.google.com/workspace/add-ons/alternate-runtimes-quickstart I've com ...

Chakra UI: Trouble with applying a personalized font from Fontsource

I recently added a new font from Fontsource called Girassol () by running the following command: npm install @fontsource/girassol In addition, I have a file named theme.ts with the following content: import { extendTheme } from "@chakra-ui/react" ...

Looking to include a badge within the nebular menu

Can someone assist me with adding a badge to the Nebular menu to display the inbox count dynamically? Any help would be greatly appreciated. Thanks! import { NbMenuItem } from '@nebular/theme'; export const MENU_ITEMS: NbMenuItem[] = [ { ti ...

Automatically dismiss modal upon submission

In the process of implementing a CRUD operation, I am trying to automatically close the modal upon submission. Using data-dismiss on the submit button only closes the modal without executing the functionality. What I need is for the functionality to execut ...

Packaging an Angular project without the need for compiling

In order to enhance reusability, I structured my Angular 6 Project into multiple modules. These modules have a reference to a ui module that contains all the style sheets (SASS) as values such as: $primary-text-color: #dde7ff !default; Although this app ...

React dynamic table

I've been experimenting with creating a dynamic table in React that allows users to add and delete rows. I need the data entered by the user to be saved, possibly using in-state management so that I can work with it later. Essentially, I'm looki ...

Angular not displaying retrieved data

Having an issue with fetching data from an API using Angular. Although the console log confirms that the data is successfully fetched, it doesn't display on the page. Any assistance would be greatly appreciated. Take a look at my code: app.component. ...

What is the process for sending an HTTP post request with a React/Typescript frontend and a C#/.Net backend?

In the frontend code, there is a user login form that accepts the strings email and password. Using MobX State Management in the userstore, there is an action triggered when the user clicks the login button to submit the strings via HTTP post. @action logi ...

Learning to implement the latest language features in JavaScript on older runtimes using TypeScript

Currently, I am faced with a dilemma in my TypeScript project involving the use of flatMap. The issue arises from the fact that this project needs to be compatible with Node.js versions as old as v10, which do not support flatMap. I had assumed that TypeS ...

How to Trigger an Angular 9 Function Using jQuery

Is there a way to trigger a function within an Angular 9 component using jQuery? I have an Angular 9 application that allows the integration of small jQuery plugins. I now need to make a basic function in the Angular app accessible to these jQuery plugins ...

Typescript classes fail to adhere to interface types

interface IFoo { method: (ha: string) => void; } class Foo implements IFoo { public method(ha) {} } The message displayed when hovering over the 'ha' parameter in the class method reads: Parameter 'ha' implicitly has an &apo ...