I have a similar use case: a wizard-style stream with 3 pages; the user fills in the data in the 1st, then confirms the data in the 2nd, and the third displays the result.
Bookmarking internal "pages" does not make sense: if the relevant data is not filled out, the user should always be redirected to the first page.
The way we solve these cases does not use routing; all N pages under ng-switch
are placed in one route:
<div ng-switch="view.state"> <div ng-switch-when="dataEntry"> <div ng-include="..."></div> </div> <div ng-switch-when="confirmation"> <div ng-include="..."></div> </div> <div ng-switch-when="outcome"> <div ng-include="..."></div> </div> </div>
And in the route controller:
angular.extend($scope, { view: { state: "dataEntry", .... }, .... });
Therefore, whenever this controller is activated, the user will see the "dataEntry" screen. This, combined with some fantastic animations, does the trick.
The ng-include
alternative is a directive for each inner page.
I don't have code right now, but I think HTML can be shortened to:
<div ng-switch="view.state"> <div ng-switch-when="dataEntry" ng-include="..."></div> <div ng-switch-when="confirmation" ng-include="..."></div> <div ng-switch-when="outcome" ng-include="..."></div> </div>
source share