如果我有以下几组路线:
server / routes.js:
import AppRoot from './app-root';
import Home from './home';
import List from './list';
const routes = [
{ component: AppRoot,
routes: [
{ path: '/',
exact: true,
component: Home
},
{ path: '/home',
component: Home
},
{ path: '/list',
component: List
}
]
}
];
export default routes;
然后在我的服务器上,我拥有:
server / index.js:
import routes from './routes';
import { RouterContext, match } from 'react-router';
const location = createLocation(req.url);
match({ routes, location }, (err, redirectLocation, renderProps) => {
const InitialView = (
<Provider store={store}>
<RouterContext {...renderProps}></RouterContext>
</Provider>
);
});
match
中的react-router
函数到底是做什么的?
我知道使用路由参数将根据位置匹配特定的组件,但是传递给match的回调函数的renderProps
是什么?
RouterContext
还能做什么?我看不到这两件事都清楚地解释了。