Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 49238

Best practice for rootPage and lazy loading

$
0
0

@alejandrocsb wrote:

We are using Ionic3 with lazy loading and we were wondering how to handle the case when the user is navigating say: mywebsite.com/example and they refresh that page.
If we use something like this, the problem is that the rootPage is first set to ExamplePage (due to the URL), but then it is automatically changed to WelcomePage.
After some changes, we got to the following solution but we aren’t sure it is the best way to do it.

@Component({
  selector: 'page-menu',
  templateUrl: 'app.html'
})
export class MyApp {
  @ViewChild(Nav) nav: Nav;

  rootPage: string = WelcomePage;

  constructor(
    private userProvider: UserProvider,
    private platform: Platform,
    private splashScreen: SplashScreen
  ) {
    this.platform.ready().then(() => {
      this.userProvider.isAuthenticated().then((isAuthenticated) => {
        this.splashScreen.hide();
        if (!isAuthenticated && this.nav.root !== LoginPage) {
          this.nav.setRoot(LoginPage);
        }
      });
    });
  }
}

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 49238

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>