Skip to content

Commit d2ad47b

Browse files
committed
add location support
1 parent d5e3f90 commit d2ad47b

File tree

3 files changed

+51
-33
lines changed

3 files changed

+51
-33
lines changed

src/index.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,14 @@ import Redirect from './redirect';
77
import PlaceHolder from './placeholder';
88
import { RouterError, Context } from 'router-async';
99

10-
export { Router, Route, Link, RootRoute, Middleware, Redirect, PlaceHolder, RouterError, Context };
10+
export {
11+
Router,
12+
Route,
13+
Link,
14+
RootRoute,
15+
Middleware,
16+
Redirect,
17+
PlaceHolder,
18+
RouterError,
19+
Context
20+
};

src/router.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,25 +32,26 @@ export default class Router extends React.Component<Props, State> {
3232
private history: any;
3333
private unlistenHistroy: any;
3434
private subscriber: any;
35-
private location: any;
35+
3636
constructor(props) {
3737
super();
3838
this.state = {
3939
Component: props.Component,
4040
props: props.props
4141
};
4242

43-
this.location = props.history.location;
4443
this.router = props.router;
4544
this.history = props.history;
4645
this.subscriber = null;
4746
}
4847
static async init({ path, routes, hooks, silent = false, ctx = new Context() }) {
4948
const plainRoutes = Router.buildRoutes(routes);
5049
const router = new RouterAsync({ routes: plainRoutes, hooks });
51-
const { route, status, params, redirect, result } = await router.run({ path, ctx, silent });
50+
const { location, route, status, params, redirect, result } = await router.run({ path, ctx, silent });
51+
5252
let props = {
5353
path,
54+
location,
5455
route,
5556
status,
5657
params,
@@ -133,18 +134,18 @@ export default class Router extends React.Component<Props, State> {
133134
go(n) {
134135
this.history.go(n);
135136
}
136-
private _locationChanged = async (location, action) => {
137+
private _locationChanged = async ({ pathname }) => {
137138
try {
138-
const { path, route, status, params, redirect, result, ctx } = await this.router.run({ path: location.pathname });
139+
const { path, location, route, status, params, redirect, result, ctx } = await this.router.run({ path: pathname });
139140
let props = {
140141
path,
142+
location,
141143
route,
142144
status,
143145
params,
144146
redirect,
145147
ctx
146148
};
147-
this.location = location;
148149
let renderCallback = Router.makeCallback(this.router, { path, route, status, params, redirect, result, ctx });
149150
this.changeComponent(result, props, renderCallback);
150151
} catch (error) {

yarn.lock

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,19 @@ encoding@^0.1.11:
1717
iconv-lite "~0.4.13"
1818

1919
fbjs@^0.8.4:
20-
version "0.8.5"
21-
resolved "https://registry.yarnpkg.com/fbjs/-/fbjs-0.8.5.tgz#f69ba8a876096cb1b9bffe4d7c1e71c19d39d008"
20+
version "0.8.6"
21+
resolved "https://registry.yarnpkg.com/fbjs/-/fbjs-0.8.6.tgz#7eb67d6986b2d5007a9b6e92e0e7cb6f75cad290"
2222
dependencies:
2323
core-js "^1.0.0"
24-
immutable "^3.7.6"
2524
isomorphic-fetch "^2.1.1"
2625
loose-envify "^1.0.0"
2726
object-assign "^4.1.0"
2827
promise "^7.1.1"
2928
ua-parser-js "^0.7.9"
3029

3130
iconv-lite@~0.4.13:
32-
version "0.4.13"
33-
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.13.tgz#1f88aba4ab0b1508e8312acc39345f36e992e2f2"
34-
35-
immutable@^3.7.6:
36-
version "3.8.1"
37-
resolved "https://registry.yarnpkg.com/immutable/-/immutable-3.8.1.tgz#200807f11ab0f72710ea485542de088075f68cd2"
31+
version "0.4.15"
32+
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.15.tgz#fe265a218ac6a57cfe854927e9d04c19825eddeb"
3833

3934
is-stream@^1.0.1:
4035
version "1.1.0"
@@ -51,15 +46,15 @@ isomorphic-fetch@^2.1.1:
5146
node-fetch "^1.0.1"
5247
whatwg-fetch ">=0.10.0"
5348

54-
js-tokens@^1.0.1:
55-
version "1.0.3"
56-
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-1.0.3.tgz#14e56eb68c8f1a92c43d59f5014ec29dc20f2ae1"
49+
js-tokens@^2.0.0:
50+
version "2.0.0"
51+
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-2.0.0.tgz#79903f5563ee778cc1162e6dcf1a0027c97f9cb5"
5752

5853
loose-envify@^1.0.0, loose-envify@^1.1.0:
59-
version "1.2.0"
60-
resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.2.0.tgz#69a65aad3de542cf4ee0f4fe74e8e33c709ccb0f"
54+
version "1.3.0"
55+
resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.3.0.tgz#6b26248c42f6d4fa4b0d8542f78edfcde35642a8"
6156
dependencies:
62-
js-tokens "^1.0.1"
57+
js-tokens "^2.0.0"
6358

6459
node-fetch@^1.0.1:
6560
version "1.6.3"
@@ -73,8 +68,8 @@ object-assign@^4.1.0:
7368
resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.0.tgz#7a3b3d0e98063d43f4c03f2e8ae6cd51a86883a0"
7469

7570
path-to-regexp@^1.6.0:
76-
version "1.6.0"
77-
resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-1.6.0.tgz#4c59cfeab5e360a2657b180730a4bb4582ecec5b"
71+
version "1.7.0"
72+
resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-1.7.0.tgz#59fde0f435badacba103a84e9d3bc64e96b9937d"
7873
dependencies:
7974
isarray "0.0.1"
8075

@@ -84,28 +79,40 @@ promise@^7.1.1:
8479
dependencies:
8580
asap "~2.0.3"
8681

82+
query-string@^4.2.3:
83+
version "4.2.3"
84+
resolved "https://registry.yarnpkg.com/query-string/-/query-string-4.2.3.tgz#9f27273d207a25a8ee4c7b8c74dcd45d556db822"
85+
dependencies:
86+
object-assign "^4.1.0"
87+
strict-uri-encode "^1.0.0"
88+
8789
88-
version "15.3.2"
89-
resolved "https://registry.yarnpkg.com/react/-/react-15.3.2.tgz#a7bccd2fee8af126b0317e222c28d1d54528d09e"
90+
version "15.4.1"
91+
resolved "https://registry.yarnpkg.com/react/-/react-15.4.1.tgz#498e918602677a3983cd0fd206dfe700389a0dd6"
9092
dependencies:
9193
fbjs "^0.8.4"
9294
loose-envify "^1.1.0"
9395
object-assign "^4.1.0"
9496

95-
router-async:
96-
version "0.2.1"
97-
resolved "https://registry.yarnpkg.com/router-async/-/router-async-0.2.1.tgz#33b47110410b62068d79db84ad83423280ab3208"
97+
router-async@0.2.x:
98+
version "0.2.2"
99+
resolved "https://registry.yarnpkg.com/router-async/-/router-async-0.2.2.tgz#7816d1c60e79bb43454f02bad73ffc925e2fbf69"
98100
dependencies:
99101
path-to-regexp "^1.6.0"
102+
query-string "^4.2.3"
103+
104+
strict-uri-encode@^1.0.0:
105+
version "1.1.0"
106+
resolved "https://registry.yarnpkg.com/strict-uri-encode/-/strict-uri-encode-1.1.0.tgz#279b225df1d582b1f54e65addd4352e18faa0713"
100107

101108
typescript@^2.1.4:
102109
version "2.1.4"
103110
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.1.4.tgz#b53b69fb841126acb1dd4b397d21daba87572251"
104111

105112
ua-parser-js@^0.7.9:
106-
version "0.7.10"
107-
resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.10.tgz#917559ddcce07cbc09ece7d80495e4c268f4ef9f"
113+
version "0.7.12"
114+
resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.12.tgz#04c81a99bdd5dc52263ea29d24c6bf8d4818a4bb"
108115

109116
whatwg-fetch@>=0.10.0:
110-
version "1.0.0"
111-
resolved "https://registry.yarnpkg.com/whatwg-fetch/-/whatwg-fetch-1.0.0.tgz#01c2ac4df40e236aaa18480e3be74bd5c8eb798e"
117+
version "2.0.1"
118+
resolved "https://registry.yarnpkg.com/whatwg-fetch/-/whatwg-fetch-2.0.1.tgz#078b9461bbe91cea73cbce8bb122a05f9e92b772"

0 commit comments

Comments
 (0)