I am looking for the best way to route between my components in Angular 2. In my application I go from page to page by submitting a form:
- Page A displays a form and a submit button to go to next step,
- Data filed by the user in page A form are used to call a backend action using ajax,
- Page B shows the result of the ajax call and a new form to go to next step (page C)...
At each step the backend can return an error and we either go back to previous page, or display an error page (fatal error).
I see two simple options to do the ajax call:
- Component A only displays the form and forward the input parameters to component B. Component B run the ajax call and display the result.
- OR component A run the ajax call with the input parameters he has and forward the result to component B for display. In case of error component A redisplay itself.
The problem with option 1 is that in case of error the backend will respond with the page A business model and an error message. Component B will have to forward the result to component A so page A can be redisplayed.
The problem with option 2 is that component A has part of the business logic of component B which is not really good for component encapsulation.
My question is: is there a good design pattern to do this? Should I use an intermediate component for example?
Thank you for your help.