Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

245
Vistas
Angular 8 - Conditional Routes Definitions

There is a need of loading the same component for two different routes.

  1. (OLDER APP) The first route (landing) belongs to the hybrid application where the Angular app or component is embedded (by placing a component selector) in some CMS application.
  2. (NEW CONVERSION) Another route (app/sub/landing) would load the same component but the route is different

Explanation I introduce a sessionStorage variable to check if the loaded app is Hybrid or not by adding below code to the CMS app.

let isHybridRouteCheck = !!sessionStorage.getItem('isHybrid');

So if the component is loading through/in CMS application then it would display isHybrid: true.

And in case of pure Angular application, it would not be getting isHybrid so the value will be false (instead of null due to !!)

Defining Routes

Hybrid Routes

const HYBRID_Routes: Routes = [
  { path: 'landing', component: LandingComponent }
...
];

Angular Routes

const PURENG_Routes: Routes = [
  {
    path: 'parent/org/companyname',
    redirectTo: 'parent/org/companyname/landing',
    pathMatch: 'full'
  },
  {
    path: 'parent/org/companyname/landing',
    component: LandingComponent
  }
]

App Module TS

Is it possible to pass routes to RouterModule as below code?

For me, the below code is throwing an error of no matching routes in case of the false value for isFwbHybridRouteCheck. It would have considered PURENG_Routes. Isn't it?

@NgModule({
    imports: [
        RouterModule.forRoot(isHybridRouteCheck ? HYBRID_Routes: PURENG_Routes, { useHash: true })
    ]
});
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The solution is simple :) When you get value from localStorage it is a string value, so when you trying convert it into boolean value equals to true always. Boolean('true') === true, Boolean('false') === true also. Try to: const isHybrid = localStorage.getItem('isHybrid') === 'true';

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda