0

Currently in our project, we are using Angular's Router to define our routes. We have a wizard-esque single page app that has next and previous buttons on each page that define which route to go to next and previous respectively. These next and previous buttons are implemented with conditional logic on each page based on user input from previous pages (e.g. if user selected "Option1 and Selection1" from a previous page, go to Page X, else go to Page Y). This works most of the time; however, as we add more pages that require more conditional logic, this could potentially get out of hand.

Is there a way to simplify this process? I've researched Angular Router guards, and while they provide a way to redirect a user to a certain page if the application doesn't have the necessary data at the time a route is called, I don't think they are what we are looking for.

3
  • How about RegularExpressions? stackoverflow.com/questions/18131834/… Commented Feb 20, 2018 at 18:43
  • Sounds like the problem isn’t pager, conditional or router but the design itself. Commented Feb 20, 2018 at 18:44
  • Sorry, I added a bit of a clarification above -- I want to go to a certain page based on answers from a previous page. Commented Feb 20, 2018 at 19:37

1 Answer 1

0

If the user isn't meant to to access page 2+ of your wizard directly, there's no reason to use Router imo. I'd go for one main component/route, a custom tree data structure that defines the user flow in it like models, components, dynamic forms, editors, api endpoints, etc used in each step. If there's too many cases for simple ng-switches, toss in ComponentFactories: https://angular.io/guide/dynamic-component-loader

Ie. I try to avoid having like Step1Component etc., and have reusable components that allow different kind of UIs built from basically just json. Though in a smaller case step1, step2, etc. -components are fine too.

Sign up to request clarification or add additional context in comments.

2 Comments

Is this kind of what you're talking about? stackoverflow.com/questions/37746516/… Edit: Or this? angular2-tree.readme.io/docs
Not a dom tree, i mean just a json array of steps, their data models (which may include metadata on which kind of editors/form elements they need), possible sub-steps (hence a tree) etc..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.