Skip to content

Commit 59340c5

Browse files
committed
render all inside Router
1 parent 4a48503 commit 59340c5

File tree

3 files changed

+8
-14
lines changed

3 files changed

+8
-14
lines changed

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Link from './link';
55
import RootRoute from './root-route';
66
import Middleware from './middleware';
77
import Redirect from './redirect';
8-
import PlaceHolder from './placeholder';
8+
import Placeholder from './placeholder';
99
import { RouterError, Context } from 'router-async';
1010

1111
export {
@@ -16,7 +16,7 @@ export {
1616
RootRoute,
1717
Middleware,
1818
Redirect,
19-
PlaceHolder,
19+
Placeholder,
2020
RouterError,
2121
Context
2222
};

src/placeholder.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export interface State {
1313
export interface Context {
1414
router: Router
1515
}
16-
export default class PlaceHolder extends React.Component<Props, State> {
16+
export default class Placeholder extends React.Component<Props, State> {
1717
context: Context;
1818
static contextTypes = {
1919
router: React.PropTypes.object.isRequired
@@ -26,7 +26,7 @@ export default class PlaceHolder extends React.Component<Props, State> {
2626
};
2727
}
2828
componentDidMount() {
29-
this.context.router.subscribe(({ Component, componentProps, path, location, renderCallback }) => {
29+
this.context.router.subscribe(function ({ Component, componentProps, path, location, renderCallback }) {
3030
this.setState({
3131
path,
3232
location,
@@ -36,6 +36,7 @@ export default class PlaceHolder extends React.Component<Props, State> {
3636
})
3737
}
3838
render() {
39-
return <this.state.Component {...this.state.componentProps} />
39+
const { Component, componentProps } = this.context.router.getState();
40+
return <Component {...componentProps} />
4041
}
4142
}

src/router.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ export default class Router extends React.Component<Props, State> {
6161
};
6262

6363
this.router = router;
64-
this.path = path;
65-
this.location = location;
6664
this.subscriber = null;
6765
}
6866
static async init(opts: initParams): Promise<initResult> {
@@ -119,7 +117,7 @@ export default class Router extends React.Component<Props, State> {
119117
return router.runHooks('render', options);
120118
}
121119
subscribe(callback: Function) {
122-
this.subscriber = callback;
120+
this.subscriber = callback.bind(this);
123121
}
124122
changeComponent({ Component, componentProps, path, location, renderCallback }) {
125123
if (this.subscriber) {
@@ -132,8 +130,6 @@ export default class Router extends React.Component<Props, State> {
132130
componentProps
133131
}, renderCallback);
134132
}
135-
this.path = path;
136-
this.location = location;
137133
}
138134
replaceComponent(Component, componentProps) {
139135
if (this.subscriber) {
@@ -146,10 +142,7 @@ export default class Router extends React.Component<Props, State> {
146142
}
147143
}
148144
getState() {
149-
return {
150-
path: this.path,
151-
location: this.location
152-
}
145+
return this.state;
153146
}
154147
render() {
155148
if (this.props.children) {

0 commit comments

Comments
 (0)