Commit 846dd5f9 authored by Sam Saccone's avatar Sam Saccone

webrx: Update routing to respect base url

Fixes #1293

Fixed in:
https://github.com/WebRxJS/WebRx/commit/712c8e820da2660ea816714901c20bd97a4284f4
parent fd4d3b68
......@@ -123,12 +123,9 @@
// setup routing
var self = this;
// Configure the Base-Url for all states (in a production-setup you would probably
// pass this from server to client via a custom query-parameter or something similar)
wx.router.baseUrl = '/examples/webrx/';
wx.router.state({
name: '$',
url: '/examples/webrx/',
onEnter: function () {
self.showMode(displayModeAll);
}
......
var wx;
(function (wx) {
"use strict";
})(wx || (wx = {}));
var wx;
(function (wx) {
"use strict";
var WeakMapEmulated = (function () {
......@@ -59,10 +63,6 @@ var wx;
"use strict";
})(wx || (wx = {}));
var wx;
(function (wx) {
"use strict";
})(wx || (wx = {}));
var wx;
(function (wx) {
var internal;
(function (internal) {
......@@ -104,7 +104,7 @@ var wx;
var wx;
(function (wx) {
"use strict";
var cssClassNameRegex = /\S+/g;
var regexCssClassName = /\S+/g;
var RxObsConstructor = Rx.Observable;
wx.noop = function () {
};
......@@ -163,6 +163,20 @@ var wx;
return false;
}
wx.isInUnitTest = isInUnitTest;
function getSearchParameters(query) {
query = query || wx.app.history.location.search.substr(1);
if (query) {
var result = {};
var params = query.split("&");
for (var i = 0; i < params.length; i++) {
var tmp = params[i].split("=");
result[tmp[0]] = decodeURIComponent(tmp[1]);
}
return result;
}
return {};
}
wx.getSearchParameters = getSearchParameters;
function args2Array(args) {
var result = [];
for (var i = 0, len = args.length; i < len; i++) {
......@@ -246,7 +260,7 @@ var wx;
classNames[_i - 2] = arguments[_i];
}
if (classNames) {
var currentClassNames = node.className.match(cssClassNameRegex) || [];
var currentClassNames = node.className.match(regexCssClassName) || [];
var index;
var i;
var className;
......@@ -4581,6 +4595,100 @@ var wx;
wx.list = list;
})(wx || (wx = {}));
var wx;
(function (wx) {
"use strict";
var MapEmulated = (function () {
function MapEmulated() {
this.cacheSentinel = {};
this.keys = [];
this.values = [];
this.cache = this.cacheSentinel;
}
Object.defineProperty(MapEmulated.prototype, "size", {
get: function () {
return this.keys.length;
},
enumerable: true,
configurable: true
});
MapEmulated.prototype.has = function (key) {
if (key === this.cache) {
return true;
}
if (this.find(key) >= 0) {
this.cache = key;
return true;
}
return false;
};
MapEmulated.prototype.get = function (key) {
var index = this.find(key);
if (index >= 0) {
this.cache = key;
return this.values[index];
}
return undefined;
};
MapEmulated.prototype.set = function (key, value) {
this.delete(key);
this.keys.push(key);
this.values.push(value);
this.cache = key;
return this;
};
MapEmulated.prototype.delete = function (key) {
var index = this.find(key);
if (index >= 0) {
this.keys.splice(index, 1);
this.values.splice(index, 1);
this.cache = this.cacheSentinel;
return true;
}
return false;
};
MapEmulated.prototype.clear = function () {
this.keys.length = 0;
this.values.length = 0;
this.cache = this.cacheSentinel;
};
MapEmulated.prototype.forEach = function (callback, thisArg) {
var size = this.size;
for (var i = 0; i < size; ++i) {
var key = this.keys[i];
var value = this.values[i];
this.cache = key;
callback.call(this, value, key, this);
}
};
Object.defineProperty(MapEmulated.prototype, "isEmulated", {
get: function () {
return true;
},
enumerable: true,
configurable: true
});
MapEmulated.prototype.find = function (key) {
var keys = this.keys;
var size = keys.length;
for (var i = 0; i < size; ++i) {
if (keys[i] === key) {
return i;
}
}
return -1;
};
return MapEmulated;
})();
var hasNativeSupport = typeof Map === "function" && Map.prototype.hasOwnProperty("forEach") && Map.prototype.hasOwnProperty("add") && Map.prototype.hasOwnProperty("clear") && Map.prototype.hasOwnProperty("devare") && Map.prototype.hasOwnProperty("has");
function createMap(disableNativeSupport) {
if (disableNativeSupport || !hasNativeSupport) {
return new MapEmulated();
}
return new Map();
}
wx.createMap = createMap;
})(wx || (wx = {}));
var wx;
(function (wx) {
"use strict";
var groupId = 0;
......@@ -6642,7 +6750,6 @@ var wx;
var Router = (function () {
function Router(domManager) {
var _this = this;
this.baseUrl = "/";
this.current = wx.property();
this.states = {};
this.pathSeparator = ".";
......@@ -6650,7 +6757,7 @@ var wx;
this.rootStateName = "$";
this.validPathRegExp = /^[a-zA-Z]([\w-_]*$)/;
this.domManager = domManager;
this.reset();
this.reset(false);
wx.app.history.onPopState.subscribe(function (e) {
var state = e.state;
var stateName = state.stateName;
......@@ -6661,6 +6768,7 @@ var wx;
});
wx.app.title.changed.subscribe(function (x) {
document.title = x;
if (_this.current() != null)
_this.replaceHistoryState(_this.current(), x);
});
}
......@@ -6727,30 +6835,45 @@ var wx;
return route.stringify(params);
return null;
};
Router.prototype.reset = function () {
Router.prototype.reset = function (enterRootState) {
if (enterRootState === void 0) { enterRootState = true; }
this.states = {};
this.root = this.registerStateInternal({
name: this.rootStateName,
route: wx.route(this.baseUrl)
url: wx.route("/")
});
if (enterRootState)
this.go(this.rootStateName, {}, { location: 2 /* replace */ });
};
Router.prototype.sync = function () {
var uri = wx.app.history.location.pathname;
Router.prototype.sync = function (url) {
if (url == null)
url = wx.app.history.location.pathname;
var keys = Object.keys(this.states);
var length = keys.length;
var params;
for (var i = 0; i < length; i++) {
var state = this.states[keys[i]];
var route = this.getAbsoluteRouteForState(state.name);
if ((params = route.parse(uri)) != null) {
if ((params = route.parse(url)) != null) {
this.go(state.name, params, { location: 2 /* replace */ });
break;
return;
}
}
if (this.current() == null)
this.reload();
};
Router.prototype.reload = function () {
this.go(this.current().name, this.current().params, { force: true, location: false });
var state;
var params;
if (this.current() != null) {
state = this.current().name;
params = this.current().params;
}
else {
state = this.rootStateName;
params = {};
}
this.go(state, params, { force: true, location: 2 /* replace */ });
};
Router.prototype.getViewComponent = function (viewName) {
var _current = this.current();
......@@ -6794,16 +6917,16 @@ var wx;
}
state = wx.extend(state, {});
this.states[state.name] = state;
if (state.route != null) {
if (typeof state.route === "string") {
state.route = wx.route(state.route);
if (state.url != null) {
if (typeof state.url === "string") {
state.url = wx.route(state.url);
}
}
else {
if (state.name !== this.rootStateName)
state.route = wx.route(parts[parts.length - 1]);
state.url = wx.route(parts[parts.length - 1]);
else
state.route = wx.route(this.baseUrl);
state.url = wx.route("/");
}
if (state.name === this.rootStateName)
this.root = state;
......@@ -6862,7 +6985,7 @@ var wx;
if (state == null) {
state = {
name: stateName,
route: wx.route(stateName)
url: wx.route(stateName)
};
}
result.push(state);
......@@ -6874,14 +6997,14 @@ var wx;
var result = null;
hierarchy.forEach(function (state) {
if (result != null) {
var route = state.route;
var route = state.url;
if (!route.isAbsolute)
result = result.concat(state.route);
result = result.concat(state.url);
else
result = route;
}
else {
result = state.route;
result = state.url;
}
});
return result;
......@@ -6957,7 +7080,7 @@ var wx;
}
});
result = Object.keys(stateParams);
result = result.concat(config.route.params);
result = result.concat(config.url.params);
}
return result;
};
......@@ -6985,6 +7108,6 @@ var wx;
})(wx || (wx = {}));
var wx;
(function (wx) {
wx.version = '0.9.79';
wx.version = '0.9.83';
})(wx || (wx = {}));
//# sourceMappingURL=web.rx.js.map
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment