Sampath
Sampath

Reputation: 65870

Set start_url on Ionic 4 PWA app instead of home page

I have developed sample PWA app using Ionic 4 and Angular PWA tool kit. I need to set home as the login page when the user clicked the app icon on his home screen on device. If the user has logged in already then he moves to the next page. i.e. after login page. Let's say dashboard. How can I do that?

Doc: https://developers.google.com/web/fundamentals/web-app-manifest/#start-url

The start_url tells the browser where your application should start when it is launched, and prevents the app from starting on whatever page the user was on when they added your app to their home screen.

I have tried this. But it always goes to the home page. Not to the login page.

manifest.json

  "display": "standalone",
  "scope": "/",
  "start_url": "/login",

routing.ts

const routes: Routes = [
  {
    path: '',
    redirectTo: 'home',
    pathMatch: 'full'
  },
  {
    path: 'home',
    loadChildren: './pages/home/home.module#HomePageModule'
  },
  {
    path: 'quotes',
    loadChildren: './pages/quotes/quotes/quotes.module#QuotesPageModule',
    canActivate: [AuthGuard]
  },
  {
    path: 'details',
    loadChildren: './pages/quotes/details/details.module#DetailsPageModule',
    canActivate: [AuthGuard]
  },
  {
    path: 'login',
    loadChildren: './pages/sign-in/login/login.module#LoginPageModule'
  },
  {
    path: 'signup',
    loadChildren: './pages/sign-in/signup/signup.module#SignupPageModule'
  }
];

Upvotes: 0

Views: 796

Answers (1)

Zadat Olayinka
Zadat Olayinka

Reputation: 471

you can just add a canActivate: [AuthGuard] to the home route definition. so by default, your app will want to go to the route /home, and if the person isn't logged in it will be redirected to /login

Alternatively, in your login route definition, add a canActivate: [ServiceToCheckIfLoggedIn], then in ServiceToCheckIfLoggedIn run your logic to check if the user is logged in, If yes, redirect where you want.

Upvotes: 2

Related Questions