Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to skip routing on a particular setRoute() call. #179

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
13 changes: 10 additions & 3 deletions lib/director/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var listener = {
mode: 'modern',
hash: dloc.hash,
history: false,
skip: false,

check: function () {
var h = dloc.hash;
Expand Down Expand Up @@ -64,9 +65,12 @@ var listener = {
}

function onchange(onChangeEvent) {
for (var i = 0, l = Router.listeners.length; i < l; i++) {
Router.listeners[i](onChangeEvent);
if (!self.skip) {
for (var i = 0, l = Router.listeners.length; i < l; i++) {
Router.listeners[i](onChangeEvent);
}
}
self.skip = false;
}

//note IE8 is being counted as 'modern' because it has the hashchange event
Expand Down Expand Up @@ -226,19 +230,22 @@ Router.prototype.explode = function () {
return v.slice(1, v.length).split("/");
};

Router.prototype.setRoute = function (i, v, val) {
Router.prototype.setRoute = function (i, v, val, skip) {
var url = this.explode();

if (typeof i === 'number' && typeof v === 'string') {
url[i] = v;
skip = val;
}
else if (typeof val === 'string') {
url.splice(i, v, s);
}
else {
url = [i];
skip = v;
}

listener.skip = skip;
listener.setHash(url.join('/'));
return url;
};
Expand Down