Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

242
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!