Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

ionic framework - How to change the app route path if a page (walkthrough) has been view once

I have app walkthrough / intro built using ion-slides which is loaded as the default page in app.routing.module.ts .

{
    path: '',
    redirectTo: 'walkthrough',
    pathMatch: 'full'
  },{
    path: 'walkthrough',
    loadChildren: () => import('./walkthrough/walkthrough.module').then(m => m.WalkthroughPageModule)
  }

I only want to show this the first time the app is launched, so my question is how do I configure the app-route in the app-routing module to set the opening page just once? I read the documentation and could not find a reference.

question from:https://stackoverflow.com/questions/65872648/how-to-change-the-app-route-path-if-a-page-walkthrough-has-been-view-once

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

For anyone in a similar situation you can add conditionals / user logic using angular route gaurds. In the Walkthrough.ts module I set the value to storage:

ngOnInit(): void {
    // save key to mark the walkthrough as visited so the next time the user vistis the app, he would be redirected to log in
    Storage.set({
      key: 'visitedWalkthrough',
      value: 'true'
    });
  }

In a walkthrough.gaurd.ts I check for same value and change the route based on same:

const { Storage } = Plugins;

@Injectable()
export class WalkthroughGuard implements CanActivate {
  constructor(private router: Router) {}

  async canActivate(): Promise<boolean> {
    const { value } = await Storage.get({ key: 'visitedWalkthrough' });

    if (value === 'true') {
      // this is a returning user, don't show him the walkthrough
      this.router.navigate(['auth']);
      return false;

    } else return true;
  }
}

Good tutorial here :


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...