Skip to content

Commit

Permalink
Merge pull request #12034 from rwjblue/expose-current-path-on-routing…
Browse files Browse the repository at this point in the history
…-service

Ensure currentRouteName and currentPath are always set.
  • Loading branch information
rwjblue committed Aug 11, 2015
2 parents 8459b2a + f3ab6c2 commit 1bd0e85
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
1 change: 1 addition & 0 deletions packages/ember-routing/lib/services/routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default Service.extend({
targetState: readOnly('router.targetState'),
currentState: readOnly('router.currentState'),
currentRouteName: readOnly('router.currentRouteName'),
currentPath: readOnly('router.currentPath'),

availableRoutes() {
return Object.keys(get(this, 'router').router.recognizer.names);
Expand Down
16 changes: 9 additions & 7 deletions packages/ember-routing/lib/system/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,14 @@ function calculatePostTransitionState(emberRouter, leafRouteName, contexts) {
}

function updatePaths(router) {
var appController = router.container.lookup('controller:application');
let infos = router.router.currentHandlerInfos;
let path = EmberRouter._routePath(infos);
let currentRouteName = infos[infos.length - 1].name;

set(router, 'currentPath', path);
set(router, 'currentRouteName', currentRouteName);

let appController = router.container.lookup('controller:application');

if (!appController) {
// appController might not exist when top-level loading/error
Expand All @@ -890,22 +897,17 @@ function updatePaths(router) {
return;
}

var infos = router.router.currentHandlerInfos;
var path = EmberRouter._routePath(infos);

if (!('currentPath' in appController)) {
defineProperty(appController, 'currentPath');
}

set(appController, 'currentPath', path);
set(router, 'currentPath', path);

if (!('currentRouteName' in appController)) {
defineProperty(appController, 'currentRouteName');
}

set(appController, 'currentRouteName', infos[infos.length - 1].name);
set(router, 'currentRouteName', infos[infos.length - 1].name);
set(appController, 'currentRouteName', currentRouteName);
}

EmberRouter.reopenClass({
Expand Down

0 comments on commit 1bd0e85

Please sign in to comment.