diff --git a/aviator.js b/aviator.js index 8936011..46f7f70 100644 --- a/aviator.js +++ b/aviator.js @@ -135,6 +135,13 @@ var Aviator = { **/ root: '', + /** + @property fallbackToHashRoutes + @type {Boolean} + @default true + **/ + fallbackToHashRoutes: true, + /** @property _navigator @type {Navigator} @@ -160,9 +167,10 @@ var Aviator = { var navigator = this._navigator; navigator.setup({ - pushStateEnabled: this.pushStateEnabled, - linkSelector: this.linkSelector, - root: this.root + fallbackToHashRoutes: this.fallbackToHashRoutes, + pushStateEnabled: this.pushStateEnabled, + linkSelector: this.linkSelector, + root: this.root }); navigator.dispatch(); @@ -285,7 +293,11 @@ Navigator.prototype = { } } - this._attachEvents(); + // If not using push state or hash routes, there's no + // need for Aviator to listen to any events. + if (this.pushStateEnabled || this.fallbackToHashRoutes) { + this._attachEvents(); + } }, /** @@ -335,7 +347,7 @@ Navigator.prototype = { @return {String} **/ getCurrentPathname: function () { - if (this.pushStateEnabled) { + if (this.pushStateEnabled || !this.fallbackToHashRoutes) { return this._removeURIRoot(location.pathname); } else { @@ -348,7 +360,7 @@ Navigator.prototype = { @return {String} **/ getCurrentURI: function () { - if (this.pushStateEnabled) { + if (this.pushStateEnabled || !this.fallbackToHashRoutes) { return this._removeURIRoot(location.pathname) + location.search; } else { @@ -363,7 +375,7 @@ Navigator.prototype = { getQueryString: function () { var uri, queryString; - if (this.pushStateEnabled) { + if (this.pushStateEnabled || !this.fallbackToHashRoutes) { return location.search || null; } else { @@ -494,10 +506,14 @@ Navigator.prototype = { this.onURIChange(); } - else { + else if (this.fallbackToHashRoutes) { if (options.replace) location.replace('#' + link); else location.hash = link; } + else { + location.replace(this.root + link); + return; + } }, /** diff --git a/src/main.js b/src/main.js index 1eba887..ab03656 100644 --- a/src/main.js +++ b/src/main.js @@ -32,6 +32,13 @@ var Aviator = { **/ root: '', + /** + @property fallbackToHashRoutes + @type {Boolean} + @default true + **/ + fallbackToHashRoutes: true, + /** @property _navigator @type {Navigator} @@ -57,9 +64,10 @@ var Aviator = { var navigator = this._navigator; navigator.setup({ - pushStateEnabled: this.pushStateEnabled, - linkSelector: this.linkSelector, - root: this.root + fallbackToHashRoutes: this.fallbackToHashRoutes, + pushStateEnabled: this.pushStateEnabled, + linkSelector: this.linkSelector, + root: this.root }); navigator.dispatch(); diff --git a/src/navigator.js b/src/navigator.js index 8f9523e..fb39365 100644 --- a/src/navigator.js +++ b/src/navigator.js @@ -34,7 +34,11 @@ Navigator.prototype = { } } - this._attachEvents(); + // If not using push state or hash routes, there's no + // need for Aviator to listen to any events. + if (this.pushStateEnabled || this.fallbackToHashRoutes) { + this._attachEvents(); + } }, /** @@ -84,7 +88,7 @@ Navigator.prototype = { @return {String} **/ getCurrentPathname: function () { - if (this.pushStateEnabled) { + if (this.pushStateEnabled || !this.fallbackToHashRoutes) { return this._removeURIRoot(location.pathname); } else { @@ -97,7 +101,7 @@ Navigator.prototype = { @return {String} **/ getCurrentURI: function () { - if (this.pushStateEnabled) { + if (this.pushStateEnabled || !this.fallbackToHashRoutes) { return this._removeURIRoot(location.pathname) + location.search; } else { @@ -112,7 +116,7 @@ Navigator.prototype = { getQueryString: function () { var uri, queryString; - if (this.pushStateEnabled) { + if (this.pushStateEnabled || !this.fallbackToHashRoutes) { return location.search || null; } else { @@ -243,10 +247,14 @@ Navigator.prototype = { this.onURIChange(); } - else { + else if (this.fallbackToHashRoutes) { if (options.replace) location.replace('#' + link); else location.hash = link; } + else { + location.replace(this.root + link); + return; + } }, /**