Skip to content

Instantly share code, notes, and snippets.

@ericf
Created July 10, 2012 15:36
Show Gist options
  • Select an option

  • Save ericf/3084149 to your computer and use it in GitHub Desktop.

Select an option

Save ericf/3084149 to your computer and use it in GitHub Desktop.
diff --git a/src/app/js/router.js b/src/app/js/router.js
index c896a51..dcb52b3 100644
--- a/src/app/js/router.js
+++ b/src/app/js/router.js
@@ -620,8 +620,7 @@ Y.Router = Y.extend(Router, Y.Base, {
// Make sure the `hash` is path-like.
if (hash && hash.charAt(0) === '/') {
- return (this.get('root') ?
- this._resolvePath(hash.substring(1)) : hash);
+ return this._joinURL(hash);
}
return '';
@@ -1058,7 +1057,7 @@ Y.Router = Y.extend(Router, Y.Base, {
**/
_save: function (url, replace) {
var urlIsString = typeof url === 'string',
- currentPath;
+ currentPath, root;
// Perform same-origin check on the specified URL.
if (urlIsString && !this._hasSameOrigin(url)) {
@@ -1066,6 +1065,7 @@ Y.Router = Y.extend(Router, Y.Base, {
return this;
}
+ // Joins the `url` with the `root`.
urlIsString && (url = this._joinURL(url));
// Force _ready to true to ensure that the history change is handled
@@ -1076,13 +1076,10 @@ Y.Router = Y.extend(Router, Y.Base, {
this._history[replace ? 'replace' : 'add'](null, {url: url});
} else {
currentPath = Y.getLocation().pathname;
+ root = this.get('root');
- // Remove the path segments from the hash-based path that already
- // exist in the page's `location.pathname`. This leads to better
- // URLs by not duplicating the `root` path segment(s).
- if (currentPath.length > 1 && url.indexOf(currentPath) === 0) {
- url = url.substring(currentPath.length);
- url.charAt(0) === '/' || (url = '/' + url);
+ if (root === currentPath || root === this._getPathRoot()) {
+ url = this.removeRoot(url);
}
// The `hashchange` event only fires when the new hash is actually
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment