diff --git a/packages/ember-routing/lib/system/router.js b/packages/ember-routing/lib/system/router.js
index 505905d63c1..033c08b9ab4 100644
--- a/packages/ember-routing/lib/system/router.js
+++ b/packages/ember-routing/lib/system/router.js
@@ -302,7 +302,11 @@ function transitionCompleted(router) {
Ember.Router.reopenClass({
map: function(callback) {
- var router = this.router = new Router();
+ var router = this.router;
+ if (!router){
+ router = this.router = new Router();
+ router.callbacks = [];
+ }
if (get(this, 'namespace.LOG_TRANSITIONS_INTERNAL')) {
router.log = Ember.Logger.debug;
@@ -310,10 +314,14 @@ Ember.Router.reopenClass({
var dsl = Ember.RouterDSL.map(function() {
this.resource('application', { path: "/" }, function() {
+ for (var i=0; i < router.callbacks.length; i++){
+ router.callbacks[i].call(this);
+ }
callback.call(this);
});
});
+ router.callbacks.push(callback);
router.map(dsl.generate());
return router;
}
diff --git a/packages/ember/tests/routing/basic_test.js b/packages/ember/tests/routing/basic_test.js
index 02a6162588e..498f8adb29e 100644
--- a/packages/ember/tests/routing/basic_test.js
+++ b/packages/ember/tests/routing/basic_test.js
@@ -35,6 +35,7 @@ module("Basic Routing", {
Ember.TEMPLATES.application = compile("{{outlet}}");
Ember.TEMPLATES.home = compile("
Hours
");
Ember.TEMPLATES.homepage = compile("Megatroll
{{home}}
");
+ Ember.TEMPLATES.camelot = compile('');
});
},
@@ -74,6 +75,53 @@ test("The Homepage", function() {
equal(Ember.$('h3:contains(Hours)', '#qunit-fixture').length, 1, "The home template was rendered");
});
+test("The Home page and the Camelot page with multiple Router.map calls", function() {
+ Router.map(function() {
+ this.route("home", { path: "/" });
+ });
+
+ Router.map(function() {
+ this.route("camelot", {path: "/camelot"});
+ });
+
+ App.HomeRoute = Ember.Route.extend({
+ });
+
+ App.CamelotRoute = Ember.Route.extend({
+ });
+
+ var currentPath;
+
+ App.ApplicationController = Ember.Controller.extend({
+ currentPathDidChange: Ember.observer(function() {
+ currentPath = get(this, 'currentPath');
+ }, 'currentPath')
+ });
+
+ App.CamelotController = Ember.Controller.extend({
+ currentPathDidChange: Ember.observer(function() {
+ currentPath = get(this, 'currentPath');
+ }, 'currentPath')
+ });
+
+ bootApplication();
+
+ Ember.run(function() {
+ router.handleURL("/camelot");
+ });
+
+ equal(currentPath, 'camelot');
+ equal(Ember.$('h3:contains(silly)', '#qunit-fixture').length, 1, "The camelot template was rendered");
+
+
+ Ember.run(function() {
+ router.handleURL("/");
+ });
+
+ equal(currentPath, 'home');
+ equal(Ember.$('h3:contains(Hours)', '#qunit-fixture').length, 1, "The home template was rendered");
+});
+
test("The Homepage register as activeView", function() {
Router.map(function() {
this.route("home", { path: "/" });