Adding Router scopes to preload data


#1

Hey,

I was playing with authentication and ember-simple-auth. In most applications, you need some authenticated pages and some unauthenticated pages.

On authenticated pages, you often need some data (the user at least). And you want to have it loaded before rendering the template.

You cannot implement the data loading on the application route model because it handles both authenticated and unauthenticated routes, thus will not load the data after a login.

So the best solution I could come up with was to have a “authenticated” route under which I nest all other routes. That way, that route takes care of loading the data prior to rendering anything. Does what I want it to. BUT, this is really ugly because now the entire code base is polluted, I need to prefix all my routes with this unauthenticated route.

I was wondering if the router could implement some sort of scope. A layer to wrap other routes and so some actions, but that doesn’t take a path option nor is represented in route path of nested routes.

this.scope('authenticated', function () {
    this.route('something');
});

Let me know what you think or if I am missing a ember feature to do what I have in mind. Thanks!