There are certain routes in my project that I don't want users to access unless they navigate to them through other routes. Right now I'm thinking I should pass a variable when I transition to the route. When the route is loaded, I should look at that variable and use it to determine whether to load the page or to redirect to a different page. transitionTo and transitionToRoute only allow you to set variables in the controller and in the model. I definitely don't want to add an attribute to my controller model just for redirecting, so I'm thinking it should set the variable in the controller. When loading the route, I can call functions like activate, beforeModel, or afterModel, but all of those run before the controller is created. This means that they wont be able to read the variable that was passed to the controller during transitionTo or transitionToRoute. In the controller I can call init which successfully reads the controller variable, but when the page is accessed correctly (through the transitionTo), the init function causes it to fail to render the first time. If I go to it later in the same session, it renders correctly.
At this point, I'm assuming that there must be a simpler way to check if the user accessed the page correctly. There doesn't seem to be any way to set a route variable during the transitionTo, but perhaps I could pass parameters and read them when the route is loaded? Any insight would be much appreciated.
Aucun commentaire:
Enregistrer un commentaire