Closed blikblum closed 7 years ago
@nathanboktae and @oliverwoodings, pls review.
So what's the use case for an abstract route with an index route? This is the same thing as just a regular parent route.
One strength about Cherrytree has been it's simplicity. Two ways to do the same thing makes it more complex.
So what's the use case for an abstract route with an index route? This is the same thing as just a regular parent route.
To create a index (default) route when a parent route is transitioned to. The behavior is the same as what ember does.
The abstract option means that it cannot be the leaf activated route. The PR does not change that fact. The leaf activated route will become the child route with empty path if any. If no child route if empty path is provided the same error is throw.
One strength about Cherrytree has been it's simplicity. Two ways to do the same thing makes it more complex.
Agreed. This was one of the reasons i choose cherrytree.
But the lack of the proposed feature creates a discrepancy between routing through the URL and the router API:
When going to an abstract route through its URL, the child route with empty path is activated
But when going to the same abstract route through router API the same does not occurs, you got a error instead
With the proposed change, both when going to an abstract route through URL or through API, will lead to same state.
Updated the tests as per request
Yup, this makes sense.
The way I saw it before was that abstract routes don't actually have urls, which is what makes them abstract. Instead that URL is for the index route. So in that sense it wasn't behaving differently when entering via URL or via router api.
Having said that, this PR makes it so that you can transition to or generate abstract routes, which can be useful and is fairly transparent. Abstract now means it will be redirected to index. Almost makes me wonder if we should rename abstract
to redirectToIndex
:)
As @nathanboktae pointed out, this does kind of create 2 ways of achieving the same thing, e.g. transitionTo('books')
and transitionTo('books.index')
routes to the same set of routes, but oh well. It is fairly transparent and if it's useful - let's try it out.
Thanks
Released as 2.4.0
Fixes #160 and #151
This change will forward transitions for abstract routes to its index route (path === '') if any
It's the same behavior as used by Ember. From its docs: "If the user navigates to /posts, the current route will be posts.index, and the posts/index template will be rendered into the {{outlet}} in the posts template."
Here's a fiddle showing the behavior (trasitioning to 'groups' activates 'groups.index') http://jsfiddle.net/qeVGG/14/