Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions aviator.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@ var Aviator = {
**/
root: '',

/**
@property fallbackToHashRoutes
@type {Boolean}
@default true
**/
fallbackToHashRoutes: true,

/**
@property _navigator
@type {Navigator}
Expand All @@ -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();
Expand Down Expand Up @@ -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();
}
},

/**
Expand Down Expand Up @@ -335,7 +347,7 @@ Navigator.prototype = {
@return {String}
**/
getCurrentPathname: function () {
if (this.pushStateEnabled) {
if (this.pushStateEnabled || !this.fallbackToHashRoutes) {
return this._removeURIRoot(location.pathname);
}
else {
Expand All @@ -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 {
Expand All @@ -363,7 +375,7 @@ Navigator.prototype = {
getQueryString: function () {
var uri, queryString;

if (this.pushStateEnabled) {
if (this.pushStateEnabled || !this.fallbackToHashRoutes) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.pushStateEnabled || this.fallbackToHashRoutes could probably be refactored into a function since it's now used so much.

return location.search || null;
}
else {
Expand Down Expand Up @@ -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;
}
},

/**
Expand Down
14 changes: 11 additions & 3 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ var Aviator = {
**/
root: '',

/**
@property fallbackToHashRoutes
@type {Boolean}
@default true
**/
fallbackToHashRoutes: true,

/**
@property _navigator
@type {Navigator}
Expand All @@ -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();
Expand Down
18 changes: 13 additions & 5 deletions src/navigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
},

/**
Expand Down Expand Up @@ -84,7 +88,7 @@ Navigator.prototype = {
@return {String}
**/
getCurrentPathname: function () {
if (this.pushStateEnabled) {
if (this.pushStateEnabled || !this.fallbackToHashRoutes) {
return this._removeURIRoot(location.pathname);
}
else {
Expand All @@ -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 {
Expand All @@ -112,7 +116,7 @@ Navigator.prototype = {
getQueryString: function () {
var uri, queryString;

if (this.pushStateEnabled) {
if (this.pushStateEnabled || !this.fallbackToHashRoutes) {
return location.search || null;
}
else {
Expand Down Expand Up @@ -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;
}
},

/**
Expand Down