Angular 2 router generates incorrect URLpaths

When navigating through my routes, I encountered an issue with the following routing setup:

const routes: Routes = [
    {
        path: '',
        component : HomeComponent,
        children: []
    },
    {
        path: 'login',
        children: [
            {
                path: '',
                component: LoginComponent
            },
            {
                path: 'with-email',
                component: LoginWithEmailComponent
            },
            {
                path: 'forgot-password',
                component: LoginForgotPasswordComponent
            }
        ]
    }   
];

Everything seemed to be working fine until I visited the "with-email" page and tried to navigate using the following code snippet:

<span><a routerLink="forgot-password"><i class="p1-icon-arrow"></i>Forgot password?</a></span>

Instead of redirecting me back to the login page and then to the forgot-password page, it created a link that looked like this:

/login/with-email/forgot-password

I was expecting it to take me directly to login/forgot-passwprd. Can anyone help me understand why this behavior is happening?

Answer №1

If the page is for email (specifically LoginWithEmailComponent), then the routerLink should be

routerLink="../forgot-password"

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

Refreshing Angular 2 + Firebase app causes user to be logged out

Just diving into Angular2, Firebase, and SPAs for the first time. I've been tasked with enhancing a Angular2 (with Firebase email&pw auth) application by adding some new features. The app primarily consists of a blog (main page), a shop (/shop), a ...

execute the angular service within the "then(function(){})" block

I have a specific requirement where I need to capture a screenshot of a view when the user clicks on a button, send it back to the backend to save as a PDF in the database, and then allow the user to download the same image. Currently, I am utilizing the D ...

Converting API data in Angular using rxjs

Hey there, I received this response from an API: { "records":[ { "id":1, "motivazione":"", "autorizzazione":false, } ] } Can anyone help me transform it to loo ...

An error occurred while attempting to generate two requests on the API

My online store consumes an API, but I am having trouble with the requests that the site is making. Every time I make a request, I receive two: one with OPTIONS and another with POST. This causes the API to become jumbled up. Can anyone offer some assist ...

Exploring the power of nested components within Angular 2

I am encountering an issue with a module that contains several components, where Angular is unable to locate the component when using the directive syntax in the template. The error message I receive states: 'test-cell-map' is not a known elemen ...

Utilizing Angular's ngIf directive to output the result of a condition

In my project, there is a unique card-list element that has the capability to display either elements from the card component or the card-edit component based on the value of the wasEditClicked property in the card component. The structure of the card-lis ...

Tips for managing transitions when the indicator is clicked by the user

I'm looking for a way to implement logic that determines whether or not a user can change the step by clicking on the indicator (the step number). I need a callback function that triggers every time there is a step change, but also allows me to preven ...

"After updating to version 3, the Ionic 3 component's JavaScript is failing to refresh properly

During the development of my Ionic 3 app, I encountered what I believe is a cache issue. It seemed to be related to lazy loading components as the problem arose after upgrading to v3 and activating lazy loading. While in development mode and using ionic se ...

In Angular components, data cannot be updated without refreshing the page when using setInterval()

Here's the Angular component I'm working with: export class UserListComponent implements OnInit, OnDestroy { private _subscriptions: Subscription; private _users: User[] = []; private _clickableUser: boolean = true; constructor( priv ...

Retrieving Information from a JSON Object using Angular 2

I'm dealing with a JSON object response. The object looks like this: {auth_token: "60a483bc0b1bc4dc0231ff0b90a67be1dad6ef45"} auth_token:"60a483bc0b1bc4dc0231ff0b90a67be1dad6ef45" proto : Object My goal is to extract the value "60a483bc0b1bc4dc0231f ...

Issue with running tests on Angular Material components causing errors

Running ng test on my Angular 8 project with Angular material components is resulting in multiple failures. The issue seems to be related to missing test cases for these scenarios. DeleteBotModalComponent > should create Failed: Template parse errors: & ...

Unable to compile Angular 5 using the AOT systemjs configuration

I've hit a roadblock in finding a solution to my issue. Maybe someone out there can lend me a hand. I'm in the process of upgrading from ng 4.4.4 to 5.0.1 and everything seems to be functioning fine in JIT mode. However, when attempting to compi ...

What is the best way to trigger an API call every 10 seconds in Angular 11 based on the status response?

I am in need of a solution to continuously call the API every 10 seconds until a success status is achieved. Once the success status is reached, the API calls should pause for 10 seconds before resuming. Below is the code I am currently using to make the A ...

To ensure that any changes made to data are reflected automatically when viewing data in Angular 2

In the process of developing an Angular 2 application, I encountered a scenario that requires special attention. The data displayed on the view is fetched from an API, with certain fields being editable by the user. These modifications can be saved using ...

Error encountered while attempting to globally install TypeScript using npm: "npm ERR! code -13"

Issue with npm error 13 Having trouble installing typescript-g package Error details: - errno: -13, - npm ERR! code: 'EACCES', - npm ERR! syscall: 'symlink', - npm ERR! path: '../lib/node_modules/typescript/bin/tsc', ...

Troubleshooting the issue of "_this is undefined" in Angular 4

connect=()=>{ this.api=new trovaSDK_Init("normal",this.businessKey,"user","<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="364345534476515b575f5f1e19565d">[email protected]</a>","","","",this.apiCallBack,thi ...

Could Typescript decorators be used as mixins?

In the process of developing a complex Angular2 application, I have created a base class that serves as the foundation for my components: export abstract class ReactiveComponent implements OnInit, OnDestroy, AfterViewInit { abstract ngOnInit(): void; ...

When a block reaches a certain height, the mat-chip-list in Angular Material is automatically shortened to fit. This feature is exclusive to

<div fxFlex="100" fxFlex.gt-sm="80" fxFlex.sm="100"> <div *ngFor="let permission of arrayOfObjectPermissions; let index = z" class="permissions-list"> <mat-card [title]=&qu ...

Karma error `An unhandled exception occurred: Cannot locate module ‘karma’` is encountered during Jest Angular testing

Looking to implement Jest testing in my Angular project, I have followed all the setup instructions provided here. Here is an excerpt from my package.json: { "name": "jest-test", "version": "0.0.0", ... } Additionally, here ...

Creating an Angular Directive for Setting the Tab Index on Enter Key Press

I need assistance with firing the Tab key event on keydown.Enter in an entire form. Currently, I am running the functions on the parent Div using the following code. Although the event is detected in the console, no changes occur on the input field (i.e., ...