Skip to content

Commit

Permalink
1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
hrasekj committed Nov 29, 2019
1 parent 61120f2 commit 9252d67
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 24 deletions.
5 changes: 3 additions & 2 deletions lib/components/Link.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,15 @@ function (_React$Component) {
children = _this$props2.children,
routerStore = _this$props2.routerStore,
activeClassName = _this$props2.activeClassName,
to = _this$props2.to,
_this$props2$to = _this$props2.to,
to = _this$props2$to === void 0 ? '' : _this$props2$to,
props = _objectWithoutProperties(_this$props2, ["params", "queryParams", "refresh", "children", "routerStore", "activeClassName", "to"]);

if (!routerStore) {
return null;
}

var href = (0, _generateUrl.routerStateToUrl)(routerStore, this.toState);
var href = to.substring(0, 1) === '#' ? to : (0, _generateUrl.routerStateToUrl)(routerStore, this.toState);

if (activeClassName) {
var index = href.indexOf('?');
Expand Down
4 changes: 2 additions & 2 deletions lib/generate-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ var routerStateToUrl = function routerStateToUrl(routerStore, toState) {

return generateUrl(route.path.pattern, params, queryParams);
} catch (e) {
console.error('Missing parameter on route ', '\'' + toState.routeName + '\'', "\n", 'Original Error: ', e.message);
return '/#(missing param on route ' + toState.routeName + ')';
console.error('Missing parameter for route ', '\'' + toState.routeName + '\'', "\n", 'Original Error: ', e.message);
return '/#(missing param for route ' + toState.routeName + ')';
}
};

Expand Down
25 changes: 15 additions & 10 deletions lib/start-router.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) r
var startRouter = function startRouter(views, rootStore) {
var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
resources = _ref.resources,
config = _objectWithoutProperties(_ref, ["resources"]);
_ref$runAllEvents = _ref.runAllEvents,
runAllEvents = _ref$runAllEvents === void 0 ? false : _ref$runAllEvents,
config = _objectWithoutProperties(_ref, ["resources", "runAllEvents"]);

var store = new _routerStore.RouterStore();
typeof rootStore === 'function' ? rootStore = rootStore(store) : rootStore.routerStore = store;
Expand Down Expand Up @@ -138,17 +140,20 @@ var startRouter = function startRouter(views, rootStore) {
}
}

newPath = newPath.concat((0, _utils.buildLookupPath)(match.route)); // add routes from previous path for onExit event trigger
newPath = newPath.concat((0, _utils.buildLookupPath)(match.route));
newPath = _toConsumableArray(new Set(newPath)); // remove duplicates
// add routes from previous path for onExit event trigger

var oldPath = (0, _utils.buildLookupPath)(store.currentRoute).reverse().filter(function (route) {
return route.isActive && !newPath.includes(route);
}); // filter all inactive routes from newPath except last one
// TODO there should be check if route params changed
});

if (!runAllEvents) {
newPath = newPath.filter(function (route, i) {
return !route.isActive || i === newPath.length - 1 && route === store.currentRoute;
});
} // build params

newPath = _toConsumableArray(new Set(newPath));
newPath = newPath.filter(function (route, i) {
return !route.isActive || i === newPath.length - 1 && route === store.currentRoute;
}); // build params

var pathParams = newPath.reduce(function (obj, route) {
return _objectSpread({}, route.defaultParams, {}, obj);
Expand All @@ -168,8 +173,8 @@ var startRouter = function startRouter(views, rootStore) {

var _loop = function _loop(_i) {
var route = newPath[_i];
fns = fns.concat((0, _utils.buildFnsArray)(route.beforeEnter, function (params, rootStore) {
store.onMatch(params, rootStore, route);
fns = fns.concat((0, _utils.buildFnsArray)(route.beforeEnter, runAllEvents && route.isActive && newPath.length - 1 !== _i || function (params, rootStore) {
return void store.onMatch(params, rootStore, route);
}));
};

Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "damidev-mobx-router",
"description": "MobX powered router for React apps",
"version": "1.1.1",
"version": "1.2.0",
"author": "Jakub Hrášek <[email protected]>",
"license": "MIT",
"bugs": {
Expand All @@ -28,8 +28,8 @@
"url": "https://github.com/damidevelopment/mobx-router.git"
},
"dependencies": {
"path-to-regexp": "^3.1.0",
"query-string": "^6.8.3"
"path-to-regexp": "^3.2.0",
"query-string": "^6.9.0"
},
"peerDependencies": {
"history": "^4.0.0",
Expand Down

0 comments on commit 9252d67

Please sign in to comment.