Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

179
Visualizações
Using Angular's ```location.back()``` redirecting me out of my angular application

My angular application opens at http://localhost:4200/scheduler. I have provided a button on homepage which on getting clicked redirect user to http://localhost:4200/cr?crId={{MONGODB_ID}}. The opened page has a Back button on it, on clicking on it I am calling this method.

  backClicked() {
    this._location.back();
  }

this method is redirecting me out of my angular application. I am not able to understand what I am doing wrong.

The routing done in app-routing.module.ts is given below as

import { NgModule } from '@angular/core';
import { PreloadAllModules, RouterModule, Routes } from '@angular/router';
import { environment } from 'src/environments/environment';
import { AuthGuard, LoginGuard } from './guard/';
import { AccessRightsGuard } from './guard/access-rights.guard';
import { UnauthorizedComponent } from './unauthorized/unauthorized.component';

export const APP_ROUTES: Routes = [
     { path: '', redirectTo: 'scheduler', pathMatch: 'full' },
     {
        path: 'scheduler',
        canActivate: [AuthGuard, AccessRightsGuard],
        loadChildren: () => import('src/app/scheduler/scheduler.module').then(m => m.SchedulerModule),
        data: { rightsId: environment.accessRights['Home Page'] }
     },
     {
       path: 'cr',
       canActivate: [AuthGuard, AccessRightsGuard],
       loadChildren:() => import('src/app/cr/cr.module').then(m => m.CrModule),
       data: { rightsId: environment.accessRights['CrewRequiremensComponent'] }
     },
    {
      path: '401',
      component: UnauthorizedComponent,
    },
    { path: '**', redirectTo: 'scheduler', pathMatch: 'full' },

The code in the routing module of scheduler module is

import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { SchedulerHomeComponent } from './scheduler.component';

const SCHEDULER_ROUTES: Routes = [
  {
    path: '',
    component: SchedulerComponent
  }
];

@NgModule({
  imports: [RouterModule.forChild(SCHEDULER_ROUTES)],
  exports: [RouterModule]
})
export class SchedulerRoutingModule {}

The code in the routing module of cr module is

import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { CrComponent } from './cr.component';

const CR: Routes = [
    {
        path: '',
        component: CrComponent
    }
];

@NgModule({
    imports: [RouterModule.forChild(CR)],
    exports: [RouterModule]
})
export class CrModule { }

about 4 years ago · Santiago Gelvez
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda