Home > Enterprise >  How to apply conditional routing in Angular where the condition is to make sure that the previous pa
How to apply conditional routing in Angular where the condition is to make sure that the previous pa

Time:02-17

I have an Angular web app where to sign up you go through different pages:

  1. Fill in your name and email
  2. Fill in your password
  3. Fill in your confirmation code

Hence the URL changes from website.com/intake to website.com/intake/signup to website.com/intake/confirmation.

My problem is that it is currently possible for a user to change the url from website.com/intake to website.com/intake/signup and finish the registration without filling the other information. I would like to prevent that but I am not sure how to use routing in this case.

I want to make sure that the user can go to the next page only if he has been to the first one and has filled in. Now I know, if I make the form fields * required it will not allow the user to go further but he will still be able to bypass that by changing the URL.

How do I solve that?

CodePudding user response:

You can use guards. Create a conditional to restrict the route you wish.

If the user hasn't filled the form, redirect him to the form.

Angular guards tutorial

  • Related