Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Different views for Desktop and mobile Angular

// Route guards would be a good solution for this purpose.

// The MobileGuard would look like this :

export class MobileGuard implements CanActivate {
    constructor(private _router: Router, private _mobileService: MobileService) {}

    canActivate(): boolean {
        const isMobile = this._mobileService.isMobile();
        if(!isMobile) {
            this._router.navigate(['/desktop']);
        }
        return isMobile;
    }
}
// The same for the DesktopGuard.

// The user trying to access any of the routes, would be redirected to the right one.

Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #Different #views #Desktop #mobile #Angular
ADD COMMENT
Topic
Name
3+8 =