NativeScript Angular encountered an error: Uncaught (in promise): There was an issue matching any routes for the URL Segment 'addpatient'

Looking to have my fab button in home.component.ts route to addpatient.component using tabs scaffolding. I've organized my addpatient folder within the home folder, here's a snapshot of my directory structure:

app directory
rest of app directory

As a beginner, it seems like I might be overlooking something simple.

home.component.ts

import { Component, OnInit, ViewContainerRef, NgModule } from 
"@angular/core";
var Sqlite = require("nativescript-sqlite");
import { registerElement } from "nativescript-angular/element-registry";
import { Fab } from "nativescript-floatingactionbutton";

import { AddPatientComponent } from "./addpatient/addpatient.component";

import { Router } from "@angular/router";
registerElement("Fab", () => Fab);


@Component({
    selector: "Home",
    moduleId: module.id,
    templateUrl: "./home.component.html"
})
export class HomeComponent implements OnInit {
    constructor(private router: Router){}

    public redirectAddPatient(){
        this.router.navigate(["addpatient]);
    }
}

home.component.html

<FAB row="1" (tap)="redirectAddPatient()" icon="res://ic_plus_white" rippleColor="#f1f1f1" class="fab-button"></FAB>

addpatient.component.ts

import { Component } from "@angular/core";
import { Patient } from "./../../objects/patient.module"
import { NativeScriptRouterModule } from "nativescript-angular/router";

@Component({
    selector: "addpatient",
    moduleId: module.id,
    templateUrl: "./addpatient.component.html"
})

export class AddPatientComponent {
    public lastname: string;

    ngOnInit(): void{
        let patient = new Patient();

        patient.setLastName(this.lastname);
        console.log("lastname: ", patient.getLastName());
    }
}

app.routing.ts

import { AddPatientComponent } from 
"./tabs/home/addpatient/addpatient.component";
import { HomeComponent } from "./tabs/home/home.component";

export const appRoutes: any = [
    {path: "", component: HomeComponent},
    {path: "addpatient", component: AddPatientComponent}
];

export const appComponents: any = [
    HomeComponent,
    AddPatientComponent
];

main.ts

import { platformNativeScriptDynamic } from "nativescript-angular/platform";

import { AppModule } from "./app.module";

import { NgModule } from "@angular/core";
import { AppComponent } from "./app.component";
import { NativeScriptRouterModule } from "nativescript-angular/router";
import { appComponents, appRoutes } from "./app.routing";

@NgModule({
    declarations: [AppComponent, ...appComponents],
    bootstrap: [AppComponent],
    imports: [
        NativeScriptRouterModule,
        NativeScriptRouterModule.forRoot(appRoutes)
    ],
})

class AppComponentModule {

}

platformNativeScriptDynamic().bootstrapModule(AppModule);

Answer №1

One issue is that you are missing a closing quote in the redirectAddPatient() function within your HomeComponent:

this.router.navigate(["addpatient*here*]);
. Additionally, it seems like you may be referencing AppModule instead of AppComponentModule when bootstrapping. I suggest making sure to include the necessary declarations and imports from AppComponentModule into your AppModule, as there doesn't appear to be a need for AppComponentModule based on my understanding.

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

transferring various items to the backend post endpoint with Angular 4 HTTP services

Greetings! I am currently facing an issue while attempting to send two objects using the HTTP POST method to the backend server My development environment consists of Angular 4, TypeScript, and ASP.NET MVC 5 Upon sending the two objects, I encounter a 50 ...

displaying a PDF in an iframe using a blob in Angular 6

I'm having trouble figuring out how to convert a blob to a PDF and display it in an iframe. The response I received from the backend is as follows (excerpt): PK !  Gæ2 [Content_Types].xml´Ko!÷úFl+§ªª<΢©6RS©[ wlá!¸Nâß;O5éÈLk³ ...

Leveraging the power of both IntelliJ and AngularCLI 6 to effortlessly import libraries using their package names

My Angular CLI 6 project consists of two components: A library containing services and components A project that utilizes this library When integrating the library into the frontend project, I typically use: import { SomeLibModule } from "some-lib"; H ...

Executing npm / http-server script

I'm currently working on a shell script that will compile an Angular app using the "ng build" command and then launch a web server to host the app from the dist folder. The web server will be started with the "http-server" command, which needs to be i ...

The introduction of an underscore alters the accessibility of a variable

When working in Angular, I encountered a scenario where I have two files. In the first file, I declared: private _test: BehaviorSubject<any> = new BehaviorSubject({}); And in the second file, I have the following code: test$: Observable<Object& ...

Can the swiping feature be turned off while the image is zoomed in?

For a project, I am utilizing the angular2-useful-swiper wrapper with iDangerous Swiper. I am seeking a way to disable the swiping functionality when an image is zoomed in. After researching the Swiper Api, I have not found any information on how to achie ...

Is it possible to utilize both $uibModal and $uibModalInstance within the same controller to create a modal popup in an Angular project incorporating TypeScript?

Being new to Angular with Typescript, I encountered an issue while trying to implement a modal popup in Angular. The problem arises when I have a dropdown menu that triggers the opening of a modal popup with two buttons, "Yes" and "No". To handle this, I h ...

Creating React components with TypeScript: Defining components such as Foo and Foo.Bar

I have a react component defined in TypeScript and I would like to export it as an object so that I can add a new component to it. interface IFooProps { title:string } interface IBarProps { content:string } const Foo:React.FC<IFooProps> = ({ ...

Strategies for incorporating Alpha into your background

Is there a way to change the background alpha rgba(0,0,0,.5) in angular material-18? I attempted to use the following code but it doesn't seem to be working: .alternate-theme-blue-navbar { .mat-toolbar-row { background: rgba(mat.get-theme-color( ...

Unable to update the <object/> element while transitioning from application/pdf to text/html

I am attempting to refresh a specific element within the DOM tree. Essentially, the TypeScript code is responsible for updating both the data and type attributes of an existing HTMLObjectElement. Here is a simplified version of the code: const textCanvas: ...

When utilizing *ngFor and Clarity's Angular components to render an array, the input's focus is lost while filtering

Having issues with my user list rendered using *ngFor. Users can filter the list by typing in the input field. Unfortunately, when the filtering process starts, the input field loses focus. I've tried various solutions found on stackoverflow (1, 2, 3 ...

Ways to hide the cell tooltip in agGrid?

Is there a way to make the tooltip invisible when hovering over a cell in agGrid? Can a specific value be set on the agGrid options to achieve this? ...

Disabling `no-dupe-keys` in ESLint does not seem to be effective

Currently, I am working on a project where I have incorporated Typescript and ESLint. However, I have encountered an issue with the error message stating: An object literal cannot have multiple properties with the same name. I am looking to disable this s ...

eliminate any redundant use of generics

Recently, I attempted to create a pull request on GitHub by adding generics to a method call. This method passes the generically typed data to an interface that determines the return type of its methods. However, the linter started flagging an issue: ERR ...

Tips for keeping your attention on the latest HTML element

Welcome to my HTML Template. <div cdkDropList class="document-columns__list list" (cdkDropListDropped)="dragDrop($event)" > <div cdkDrag class="list__box" ...

Exploring the Angular 2 Framework by Streaming Data from a RESTful API

Is it possible to easily handle a continuously streaming data feed in angular2? I am working on a chat application with a server written in go and a client implemented in angular2. To enable real-time updates, I have set up an endpoint that maintains the c ...

Angular - CSS Grid - Positioning columns based on their index values

My goal is to create a CSS grid with 4 columns and infinite rows. Specifically, I want the text-align property on the first column to be 'start', the middle two columns to be 'center', and the last column to be 'end'. The cont ...

How to remove a specific type from a generic type in Typescript without using Exclude<>?

I am looking for a solution to prevent my function from working with Moment objects when storing values in local storage. Currently, the function dynamically stringifies and stores values, but I want to exclude Moment objects from being processed. Here is ...

Checking the validity of a template form in Angular 2 when a button is clicked

I just started learning Angular 2 and I'm working on a simple template with two text fields that need to be required field validated. Login Form <form #loginForm="ngForm" (ngSubmit)="onSubmit(loginForm)" novalidate> <div class="containe ...

Creating a unique abstract element for cycling through a collection

I have multiple components that all have a similar structure: import { Component, Input, Output } from '@angular/core'; import { Subject } from 'rxjs'; import { Tag } from 'src/app/models'; @Component({ selector: 'app ...