Is it possible for the app-routing.module.ts to have two paths with :/id?

When attempting to access the maindetail and childdetails pages using :/id, I encountered an issue on localhost where the desired card was not displaying on the maindetail page.

The goal is to be able to click on the name "aniq" in the dashboard (image 1) and have it direct to the child detail page. However, upon reaching the child detail page, the intended card is not appearing (image 2). Strangely, upon revisiting the link localhost:8100/maindetail (image 3), the card shows up. I am unsure what the problem may be. Any assistance would be greatly appreciated. Thank you.

Below is my app-routing.module.ts:

const routes: Routes = [
  { path: 'login', loadChildren: './login/login.module#LoginPageModule' },
  { path: 'register', loadChildren: './register/register.module#RegisterPageModule' },
  { path: '', redirectTo: 'login', pathMatch: 'full' },
  { path: '', loadChildren: './pages/tabs/tabs.module#TabsPageModule' },
   { path: 'maindetail', loadChildren: './pages/maindetail/maindetail.module#MaindetailPageModule' },
  { path: 'maindetail/:id', loadChildren: './pages/maindetail/maindetail.module#MaindetailPageModule' },
  { path: 'childdetails', loadChildren: './pages/childdetails/childdetails.module#ChilddetailsPageModule' },
  { path: 'childdetails/:id', loadChildren: './pages/childdetails/childdetails.module#ChilddetailsPageModule' },
];

image 1

image 2 image 3

Answer №1

Absolutely, in Angular you have the flexibility to create multiple routes with parameters. It's even possible to include multiple parameters within the same route!

When working with lazy-loading modules, it is common to have a separate routing module within that particular module. To clarify this concept further, let me provide an example for better understanding.

app-routing.module.ts

Let's consider the child details module for our discussion. In the snippet below, we define a single route for /childdetails:

const routes: Routes = [
  { path: 'childdetails', loadChildren: 
 './pages/childdetails/childdetails.module#ChilddetailsPageModule' },
];

However, if we intend to incorporate an ID passed as a route parameter, we can create a file named childdetails-routing.module.ts within our module directory. The structure inside this file would closely resemble the following:

const routes: Routes = [
  { path: ':id', component: yourChildDetailComponent },
];

For precise instructions, it may be beneficial to consult the official documentation at https://angular.io/guide/lazy-loading-ngmodules#configure-the-feature-modules-routes

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

Managing middleware in tRPC: Utilizing multiple methods for a single route call?

We're currently working on a group project with a tight deadline of just a few weeks. Our team has opted to utilize the T-3 stack for this project and have chosen tRPC as the server framework. While I am familiar with express, I am finding it challeng ...

The CSS for SVG circles breaks in Firefox, causing the browser to strip away the radius property

Currently, I am working on creating a progress ring using SVG and CSS. It is functioning well in Chrome; however, Firefox (61.0.1 (64-bit)) is giving me trouble as it does not display the circle. I attempted to apply the method from this question but did n ...

Activate the button in Angular2 when any character other than a space is inputted

I'm working on a comment section in the form of a text area and I need to enable another button when a user starts typing characters (excluding spaces) into the textarea. How can I achieve this in Angular 2? I have managed to make it work, but my iss ...

What is the method for nesting data within a component's child>child>child structure?

In the structure I am working with, there is a hierarchy: Root component buttons (menu search component) - an input field for searching Widgets (widget component ) (Cats widget) - displays what is input in the menu search here. My challen ...

No TypeScript error in Angular app when assigning a string to a number data type

Today, I encountered some confusion when my app started acting strangely. It turns out that I mistakenly assigned a string to a number without receiving any error alerts. Any thoughts on why this happened? id:number; Later on: this.id = ActiveRoute.params ...

We are considering implementing Angular 2, however our current application is built with Angular 1.x. Are there any resources available for integrating Angular 2 with Angular 1.x?

Currently, rewriting our app is not an option and we are also hesitant to develop a new app solely for angular 2. We are exploring alternatives to integrate both frameworks gradually for a smoother migration process. ...

Troubleshooting issue in Angular with loading data before rendering the view

Have you ever come across an issue where you navigate to a component and the table appears empty with no data? I noticed that the component/table is displayed, and the data seems to be in the state (session storage) and loaded. I can only see them if I re ...

Make TextField with type number forcibly show dot as decimal separator

I am currently utilizing the material-ui library to display a TextField component in my react application. Strangely, all instances of <TextField type="number /> are displaying decimal separators as commas (,) instead of dots (.), causing confusion f ...

Navigating the missing "length" property when dealing with partial functions generated using lodash's partialRight

I've been utilizing MomentTimezone for time manipulation within the browser. My development stack includes TypeScript and Lodash. In my application, there is an accountTimezone variable set on the window object which stores the user's preferred ...

The type 'Function' does not contain any construct signatures.ts

Struggling to transition my JS code to TS, specifically with a class called Point2D for handling 2 dimensional points. Encountering an error message stating Type 'Function' has no construct signatures.ts(2351). Any insights on what might be going ...

What is the best way to test the validity of a form while also verifying email availability?

I am currently working on implementing async validation in reactive forms. My goal is to disable the submit button whenever a new input is provided. However, I am facing an issue where if duplicate emails are entered, the form remains valid for a brief per ...

Angular Obsidian Theme

Hey there! I've successfully implemented a toggle button that switches my Ionic 3 app to dark mode. However, I'm unsure about where exactly I should define the global class [class.dark-theme]="dark". It's essential for this class to be in th ...

Tips for importing a package in Angular 2 with Visual Studio 2015

After running npm install --save camelCase, I have successfully installed the package. Now, I am looking to utilize it in my project along with TypeScript version 2.0.3. In order to import the package, I added the following line: import * as camelcase ...

Tips for updating values in an Angular model and pushing it to an array with the specified index

I am currently facing an issue with my Angular Model as I attempt to add it to an array in order to generate repeated fields. The purpose of this array is to then be looped through in order to create HTML fields within a component. However, during the proc ...

How to reference an object from an external file in TypeScript using Ionic 2 and Angular 2

I am currently developing a mobile application with Ionic2 and have integrated a simple online payment service called Paystack for processing payments. The way it operates is by adding a js file to your webpage and then invoking a function. <script> ...

Adding child arrays to a parent array in Angular 8 using push method

Upon filtering the data, the response obtained inside the findChildrens function is as follows: My expectation now is that if the object length of this.newRegion is greater than 1, then merge the children of the second object into the parent object's ...

The specified data type is not compatible with the current context and cannot be treated as an array

Just starting out with TypeScript and I've encountered an issue that's preventing me from successfully building my app. Everything runs smoothly on my local environment, but as soon as I try to build it, an error pops up. Here's a snippet o ...

Tips for confirming a sub string is present in an array using JavaScript/TScript

I am currently testing for the presence of a SubString within an array. In my test, I am asserting using: expect(classList).toContain('Rail__focused') However, I encountered the following error: Error: expect(received).toContain(expected // inde ...

Creating a JWT token in Angular 2 Typescript: A step-by-step guide

Inside Component import * as jwt from 'jsonwebtoken'; var secretKey = privateKey; var accessToken = jwt.sign({ user: 'johnDoe' }, secretKey, { algorithm: 'RS256' }); I encountered the following issue. Uncaught (in promise) ...

Encountering an error in Chrome where the property 'command' is undefined

Currently utilizing typescript and encountered an error in the chrome console: Error found in event handler for (unknown): TypeError: Unable to access property 'command' as it is undefined at chrome-extension://somethingsomethingsometh ...