I have 2 components. 1 is the registration component, 2 is the main component. And before the main component, I need to open the register component. That is, a person visits the site link, and the register component opens for him. After registration, the main component opens.
RouterModule.forRoot ([
{ path: '', redirectTo: 'registration', pathMatch: 'full' },
{ path: 'registration', component: RegisterComponent }
])
CodePudding user response:
In your case, you need to create 2 component:
- Main component ("e.g: User Component")
- Registration Component
After you create that component, you need to create 2 Guard,
- Ensure Register Guard or Ensure authenticate guard
- Ensure Not Register Guard or Ensure not authenticate guard
After you create 2 guard and 2 component, now you can use the first guard to main component and the second guard to registration component.
For example you can look at here:
Code: https://stackblitz.com/edit/angular-ivy-qh67uh
Preview: https://angular-ivy-qh67uh.stackblitz.io
I hope it can help.