WIP: this is something I'm still considering – feedback welcome (yo @PascalPrecht )
I think this would solve several problems, so I'm proposing it as a general solution.
Rationalle
Right now, the set of components that we need to instantiate is dynamically built up on the client. Each component only knows how to map its own level of routing. This is great, because it means we can easily re-mount and reuse routable components.
But in order to open the door for the possibility of server-side rendering, there needs to be a way to statically map a URL to the set of components it needs. This is important that this mapping is static and declarative. This is because some apps might not want to run JS code for router components on the server – like apps which are not written with node.
It's also important so that a parent component can link to a child component. Right now, this is broken.
Other routing systems avoid this problem by consolidating all routing information into a single place before the app bootstraps. This solution is good, but it loses some of the benefits of our earlier approach.
Concrete example of the problem
TODO
Implementation
This is what an app would look like in 1.x:
Before:
function MyController($router) {
$router.config([ ... ]);
/* controller init */
}
After:
MyController.$router = [ ... ];
function MyController() {
/* controller init */
}
With AtScript, you could use annotations to make this a little prettier:
@router([ ... ])
class MyComponent() { ... }