Skip to content

Commit

Permalink
fix: bugs related to getting location
Browse files Browse the repository at this point in the history
  • Loading branch information
troch committed Jul 9, 2015
1 parent 1a7246d commit 4c6a1d2
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 29 deletions.
12 changes: 4 additions & 8 deletions dist/browser/router5.js
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ var Router5 = (function () {
this.rootNode = routes instanceof RouteNode ? routes : new RouteNode('', '', routes);
this.activeComponents = {};
this.options = opts;
this.base = window.location.pathname;
this.base = window.location.pathname.replace(/^\/$/, '');

return this;
}
Expand Down Expand Up @@ -561,7 +561,7 @@ var Router5 = (function () {
this.started = true;

// Try to match starting path name
var startPath = this.getLocation().replace(new RegExp('^' + this.base), '');
var startPath = this.getLocation();
var startState = this.matchPath(startPath);

if (startState) {
Expand Down Expand Up @@ -796,7 +796,7 @@ var Router5 = (function () {
* @private
*/
value: function getLocation() {
return this.options.useHash ? window.location.hash.replace(/^#/, '') : window.location.pathname;
return this.options.useHash ? window.location.hash.replace(/^#/, '') : window.location.pathname.replace(new RegExp('^' + this.base), '');
}
}, {
key: 'buildUrl',
Expand Down Expand Up @@ -839,10 +839,6 @@ var Router5 = (function () {
}, {
key: '_transition',

/**
*
*/

/**
* @private
*/
Expand All @@ -851,7 +847,7 @@ var Router5 = (function () {

if (!fromState) {
this.lastKnownState = toState;
this._invokeListeners('', toState, fromState);
this._invokeListeners('*', toState, fromState);
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion dist/browser/router5.min.js

Large diffs are not rendered by default.

12 changes: 4 additions & 8 deletions dist/commonjs/router5.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var Router5 = (function () {
this.rootNode = routes instanceof _routeNode2['default'] ? routes : new _routeNode2['default']('', '', routes);
this.activeComponents = {};
this.options = opts;
this.base = window.location.pathname;
this.base = window.location.pathname.replace(/^\/$/, '');

return this;
}
Expand Down Expand Up @@ -119,7 +119,7 @@ var Router5 = (function () {
this.started = true;

// Try to match starting path name
var startPath = this.getLocation().replace(new RegExp('^' + this.base), '');
var startPath = this.getLocation();
var startState = this.matchPath(startPath);

if (startState) {
Expand Down Expand Up @@ -354,7 +354,7 @@ var Router5 = (function () {
* @private
*/
value: function getLocation() {
return this.options.useHash ? window.location.hash.replace(/^#/, '') : window.location.pathname;
return this.options.useHash ? window.location.hash.replace(/^#/, '') : window.location.pathname.replace(new RegExp('^' + this.base), '');
}
}, {
key: 'buildUrl',
Expand Down Expand Up @@ -397,10 +397,6 @@ var Router5 = (function () {
}, {
key: '_transition',

/**
*
*/

/**
* @private
*/
Expand All @@ -409,7 +405,7 @@ var Router5 = (function () {

if (!fromState) {
this.lastKnownState = toState;
this._invokeListeners('', toState, fromState);
this._invokeListeners('*', toState, fromState);
return true;
}

Expand Down
12 changes: 4 additions & 8 deletions dist/umd/router5.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
this.rootNode = routes instanceof _RouteNode['default'] ? routes : new _RouteNode['default']('', '', routes);
this.activeComponents = {};
this.options = opts;
this.base = window.location.pathname;
this.base = window.location.pathname.replace(/^\/$/, '');

return this;
}
Expand Down Expand Up @@ -126,7 +126,7 @@
this.started = true;

// Try to match starting path name
var startPath = this.getLocation().replace(new RegExp('^' + this.base), '');
var startPath = this.getLocation();
var startState = this.matchPath(startPath);

if (startState) {
Expand Down Expand Up @@ -361,7 +361,7 @@
* @private
*/
value: function getLocation() {
return this.options.useHash ? window.location.hash.replace(/^#/, '') : window.location.pathname;
return this.options.useHash ? window.location.hash.replace(/^#/, '') : window.location.pathname.replace(new RegExp('^' + this.base), '');
}
}, {
key: 'buildUrl',
Expand Down Expand Up @@ -404,10 +404,6 @@
}, {
key: '_transition',

/**
*
*/

/**
* @private
*/
Expand All @@ -416,7 +412,7 @@

if (!fromState) {
this.lastKnownState = toState;
this._invokeListeners('', toState, fromState);
this._invokeListeners('*', toState, fromState);
return true;
}

Expand Down
10 changes: 6 additions & 4 deletions modules/Router5.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default class Router5 {
this.rootNode = routes instanceof RouteNode ? routes : new RouteNode('', '', routes)
this.activeComponents = {}
this.options = opts
this.base = window.location.pathname
this.base = window.location.pathname.replace(/^\/$/, '')

return this
}
Expand Down Expand Up @@ -87,7 +87,7 @@ export default class Router5 {
this.started = true

// Try to match starting path name
let startPath = this.getLocation().replace(new RegExp('^' + this.base), '');
let startPath = this.getLocation();
let startState = this.matchPath(startPath)

if (startState) {
Expand Down Expand Up @@ -279,7 +279,9 @@ export default class Router5 {
* @private
*/
getLocation() {
return this.options.useHash ? window.location.hash.replace(/^#/, '') : window.location.pathname
return this.options.useHash
? window.location.hash.replace(/^#/, '')
: window.location.pathname.replace(new RegExp('^' + this.base), '')
}

/**
Expand Down Expand Up @@ -320,7 +322,7 @@ export default class Router5 {
_transition(toState, fromState) {
if (!fromState) {
this.lastKnownState = toState
this._invokeListeners('', toState, fromState)
this._invokeListeners('*', toState, fromState)
return true
}

Expand Down

0 comments on commit 4c6a1d2

Please sign in to comment.