Skip to content

Commit

Permalink
add buildRouteInfoMetadata docs
Browse files Browse the repository at this point in the history
  • Loading branch information
chadhietala committed Dec 10, 2018
1 parent c0accdc commit 56d74e0
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/@ember/-internals/routing/lib/system/route-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@
@public
*/

/**
Will contain the result `Route#buildRouteInfoMetadata`
for the corresponding Route.
@property {Any} metadata
@category ember-routing-build-routeinfo-metadata
@public
*/

/**
A reference to the parent route's RouteInfo.
This can be used to traverse upward to the topmost
Expand Down
35 changes: 35 additions & 0 deletions packages/@ember/-internals/routing/lib/system/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2559,6 +2559,41 @@ if (EMBER_ROUTING_ROUTER_SERVICE && ROUTER_EVENTS) {

if (EMBER_ROUTING_BUILD_ROUTEINFO_METADATA) {
Route.reopen({
/**
Allows you to produce custom metadata for the route.
The return value of this method will be attatched to
its corresponding RouteInfoWithAttributes obejct.
Example
```app/routes/posts/index.js
import Route from '@ember/routing/route';
export default Route.extend({
buildRouteInfoMetadata() {
return { title: 'Posts Page' }
}
});
```
```app/routes/application.js
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
export default Route.extend({
router: service('router'),
init() {
this._super(...arguments);
this.router.on('routeDidChange', transition => {
document.title = transition.to.metadata.title;
// would update document's title to "Posts Page"
});
}
});
```
@return any
@category ember-routing-build-routeinfo-metadata
*/
buildRouteInfoMetadata() {},
});
}
Expand Down

0 comments on commit 56d74e0

Please sign in to comment.