Skip to content

Commit

Permalink
Add hashbang support to go() by introducing the "hashbang" mode to ap…
Browse files Browse the repository at this point in the history
…p-router.

app-router already supports hash changes with hashbang URLs but not when navigating.
This commit will make .go() prefix paths with "#!" instead of "#" if app-router has the 
attribute mode="hashbang".
  • Loading branch information
Patrik Kullman committed Mar 20, 2015
1 parent 8ec35ee commit efd91d3
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/app-router.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
var isIE = 'ActiveXObject' in window;
var previousUrl = {};

// <app-router [init="auto|manual"] [mode="auto|hash|pushstate"] [trailingSlash="strict|ignore"] [typecast="auto|string"] [bindRouter]></app-router>
// <app-router [init="auto|manual"] [mode="auto|hash|hashbang|pushstate"] [trailingSlash="strict|ignore"] [typecast="auto|string"] [bindRouter]></app-router>
var AppRouter = Object.create(HTMLElement.prototype);
AppRouter.util = utilities;

Expand Down Expand Up @@ -35,7 +35,7 @@
router.setAttribute('trailingSlash', 'strict');
}

// mode="auto|hash|pushstate"
// mode="auto|hash|hashbang|pushstate"
if (!router.hasAttribute('mode')) {
router.setAttribute('mode', 'auto');
}
Expand Down Expand Up @@ -115,8 +115,12 @@
// }
AppRouter.go = function(path, options) {
if (this.getAttribute('mode') !== 'pushstate') {
// mode == auto or hash
path = '#' + path;
// mode == auto, hash or hashbang
if (this.getAttribute('mode') === 'hashbang') {
path = '#!' + path;
} else {
path = '#' + path;
}
}
if (options && options.replace === true) {
window.history.replaceState(null, null, path);
Expand Down

0 comments on commit efd91d3

Please sign in to comment.