Reputation: 17480
I've got a set of routes. Some routes I want to redirect in the case that the user is not authenticated, and others I want to redirect if the user IS authenticated.
The AuthenticatedRoute case is working, so I've implemented the following Routes for the other case:
App.NotAuthenticatedRoute = Ember.Route.extend
beforeModel: (transition) ->
if App.Auth.get('signedIn')
return Ember.RSVP.reject();
events: {
error: (reason, transition) ->
@transitionTo('home')
}
App.RegistrationRoute = App.NotAuthenticatedRoute.extend
setupController: (controller) ->
controller.set('email', null)
controller.set('password', null)
controller.set('passwordConfirmation', null)
App.LoginRoute = App.NotAuthenticatedRoute.extend
Each route is in it's own file in my /routes directory. RegistrationRoute works exactly as expected. LoginRoute, however, throws an error:
Uncaught TypeError: Cannot call method 'extend' of undefined login_route.js?body=1:2
(anonymous function)
The only reason I can think of for this is that LoginRoute
is being interpreted before NotAuthenticatedRoute
is loaded. If I change NotAuthenticatedRoute
in not_authenticated_route.js.coffee
to something like AntiAuthenticatedRoute
in anti_authenticated_route.js.coffee
, everything works.
How might I handle the load order?
I also solved the issue by putting my routes intended to be inherited from in an extensions directory, which gets loaded before the other files in the routes directory, which might be a decent workaround for the problem.
Upvotes: 1
Views: 471
Reputation: 10077
Assuming that App.NotAuthenticatedRoute
is defined in not_authenticated_route.js
then add a require statement in your definition of App.LoginRoute
:
#= require not_authenticated_route
App.LoginRoute = App.NotAuthenticatedRoute.extend
Upvotes: 1