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

246
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
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