There is a need of loading the same component for two different routes.
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 })
]
});
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';