Issue
my goal is to separate desktop
and mobile
page. The reason is that the desktop
page UX flow is "scroll to section". Meanwhile, the mobile
page UX flow is "navigate to the next section".
The problem:
- The
desktop
user will loadmobile
page. Same goes for themobile
user.
This is the visual diagram of the current solution:
- there is a
main
page andget-device-type
service. - the
main
page will render thedesktop
page or themobile
page.
What I've tried:
- use
canLoad
fordesktop
page.
My expectation:
- When the
desktop
user visit pathcheckout/1
, it will load thedesktop
page. - When the
mobile
user visit pathcheckout/1
, it will not load thedesktop
page but instead load themobile
page.
My actual result:
- When the
desktop
user visit pathcheckout/1
, it will load thedesktop
page. - When the
mobile
user visit pathcheckout/1
, it will not load any page.
checkout-page-routing.module.ts
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { IsDesktopGuard } from '../../../domain/usecases/is-desktop/is-desktop.guard';
const routes: Routes = [
{
path: '',
loadChildren: () => import("../checkout-scroll-page/checkout-scroll-page.module").then(m => m.CheckoutScrollPageModule),
canLoad: [IsDesktopGuard]
},
{
path: '',
loadChildren: () => import("../checkout-navigate-page/checkout-navigate-page.module").then(m => m.CheckoutNavigatePageModule)
}
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class CheckoutPageRoutingModule { }
Solution
You can conditionally do loadChildren
based on the device?
const isMobile = {
Android: function () {
return navigator.userAgent.match(/Android/i);
},
BlackBerry: function () {
return navigator.userAgent.match(/BlackBerry/i);
},
iOS: function () {
return navigator.userAgent.match(/iPhone|iPad|iPod/i);
},
Opera: function () {
return navigator.userAgent.match(/Opera Mini/i);
},
Windows: function () {
return navigator.userAgent.match(/IEMobile/i) || navigator.userAgent.match(/WPDesktop/i);
},
any: function () {
return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
}
};
const routes: Routes = [
{
path: 'desktop',
loadChildren: () => {
if (!isMobile.any()) {
return import("../checkout-scroll-page/checkout-scroll-page.module").then(m => m.CheckoutScrollPageModule);
} else {
return import("../checkout-navigate-page/checkout-navigate-page.module").then(m => m.CheckoutNavigatePageModule);
}
},
},
];
Answered By - Naren Murali
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.