Skip to content

Commit ced0cfd

Browse files
committed
added silent option and updated deps
1 parent 20ac30a commit ced0cfd

File tree

3 files changed

+15
-27
lines changed

3 files changed

+15
-27
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@
2626
},
2727
"dependencies": {
2828
"react": "15.x.x",
29-
"router-async": "0.1.x"
29+
"router-async": "0.2.x"
3030
}
3131
}

src/router.tsx

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ export default class Router extends React.Component<Props, State> {
4343
this.router = props.router;
4444
this.history = props.history;
4545
}
46-
static async init({ path, routes, hooks, ctx = new Context() }) {
46+
static async init({ path, routes, hooks, silent = false, ctx = new Context() }) {
4747
const plainRoutes = Router.buildRoutes(routes);
4848
const router = new RouterAsync({ routes: plainRoutes, hooks });
49-
const { route, status, params, redirect, result } = await router.resolve({ path, ctx });
49+
const { route, status, params, redirect, result } = await router.run({ path, ctx, silent });
5050
let props = {
5151
path,
5252
route,
@@ -66,26 +66,14 @@ export default class Router extends React.Component<Props, State> {
6666
}
6767
}
6868
static buildRoutes(routes) {
69-
if (!Array.isArray(routes)) {
70-
routes = routes.props.children;
71-
}
69+
if (!Array.isArray(routes)) routes = routes.props.children;
7270
return deepMap(routes, route => {
7371
const result: Route = {};
74-
if (route.props.path) {
75-
result.path = route.props.path;
76-
}
77-
if (route.props.action) {
78-
result.action = route.props.action;
79-
}
80-
if (route.props.status) {
81-
result.status = route.props.status;
82-
}
83-
if (route.props.to) {
84-
result.to = route.props.to;
85-
}
86-
if (route.props.children) {
87-
result.childs = Array.isArray(route.props.children) ? route.props.children : [route.props.children];
88-
}
72+
if (route.props.path) result.path = route.props.path;
73+
if (route.props.action) result.action = route.props.action;
74+
if (route.props.status) result.status = route.props.status;
75+
if (route.props.to) result.to = route.props.to;
76+
if (route.props.children) result.childs = Array.isArray(route.props.children) ? route.props.children : [route.props.children];
8977
return result;
9078
});
9179
}
@@ -126,7 +114,7 @@ export default class Router extends React.Component<Props, State> {
126114
}
127115
private _locationChanged = async (location, action) => {
128116
try {
129-
const { path, route, status, params, redirect, result, ctx } = await this.router.resolve({ path: location.pathname });
117+
const { path, route, status, params, redirect, result, ctx } = await this.router.run({ path: location.pathname });
130118
let props = {
131119
path,
132120
route,

yarn.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,15 @@ [email protected]:
9090
loose-envify "^1.1.0"
9191
object-assign "^4.1.0"
9292

93-
router-async@0.1.x:
94-
version "0.1.0"
95-
resolved "https://registry.yarnpkg.com/router-async/-/router-async-0.1.0.tgz#109227c67ab35745fcb974ac52e0c1a41e66ec58"
93+
router-async:
94+
version "0.2.1"
95+
resolved "https://registry.yarnpkg.com/router-async/-/router-async-0.2.1.tgz#33b47110410b62068d79db84ad83423280ab3208"
9696
dependencies:
9797
path-to-regexp "^1.6.0"
9898

9999
typescript@next:
100-
version "2.1.0-dev.20161024"
101-
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.1.0-dev.20161024.tgz#8c9bd571ce990a1bc01444e28b5124658145b83a"
100+
version "2.1.0-dev.20161027"
101+
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.1.0-dev.20161027.tgz#f6456102956dee194398fa1ad093b944c8db4f0a"
102102

103103
ua-parser-js@^0.7.9:
104104
version "0.7.10"

0 commit comments

Comments
 (0)