Added router and createElement to MatchState. Added tests to demonstrate SSR using match and RouterContext

This commit is contained in:
Jack Moore
2016-08-28 18:27:36 -05:00
parent 85d3e4e5c6
commit 0bfbcce5f3
2 changed files with 17 additions and 1 deletions
+15 -1
View File
@@ -7,8 +7,9 @@
import * as React from "react"
import * as ReactDOM from "react-dom"
import {renderToString} from "react-dom/server";
import { browserHistory, hashHistory, createMemoryHistory, withRouter, Router, Route, IndexRoute, Link} from "react-router"
import { browserHistory, hashHistory, createMemoryHistory, match, withRouter, Router, RouterContext, Route, IndexRoute, Link} from "react-router"
import { routerShape, locationShape } from "react-router/lib/PropTypes"
interface MasterContext {
@@ -99,3 +100,16 @@ ReactDOM.render((
</Route>
</Router>
), document.body)
const history = createMemoryHistory("baseurl");
const routes = (
<Route path="/" component={Master}>
<IndexRoute component={DashboardWithRouter} />
<Route path="users" component={Users}/>
</Route>
);
match({history, routes, location: "baseurl"}, (error, redirectLocation, renderProps) => {
renderToString(<RouterContext {...renderProps} />);
});
+2
View File
@@ -275,6 +275,8 @@ declare namespace ReactRouter {
}
interface MatchState extends RouterState {
history: History
router: Router
createElement: (component: RouteComponent, props: Object) => any
}
function match(args: MatchArgs, cb: (error: any, nextLocation: H.Location, nextState: MatchState) => void): void