Express Url没有';无法匹配react路由器中的任何路由
我正在使用Express和React构建一个同构应用程序。我想将react用于具有固定路径的一系列url,如:Express Url没有';无法匹配react路由器中的任何路由,express,reactjs,react-router,Express,Reactjs,React Router,我正在使用Express和React构建一个同构应用程序。我想将react用于具有固定路径的一系列url,如:hostname/admin/xxx,hostname/admin/yyyy,hostname/admin/zzz 在Express中,路由器是: // in server.js file app.use('/admin', admin); // in admin.js router file router.get('*', (req, res) => { match()
hostname/admin/xxx
,hostname/admin/yyyy
,hostname/admin/zzz
在Express中,路由器是:
// in server.js file
app.use('/admin', admin);
// in admin.js router file
router.get('*', (req, res) => {
match() // react-router's match method
}
在react router
的routes
文件中,它是:
<Route path='/' component={Admin}>
<Route path='child' component={Child} />
</Route>
服务器呈现无法匹配任何路由
我认为问题在于,对于服务器渲染,
路径是'/'
,而对于客户端则是'/admin'
。除了使用app.use('/',admin)
在Express中,我如何修复它?我的最终解决方案是将'/admin'
添加到匹配()
方法中的位置
属性:
match({
routes,
location: '/admin' + req.url
}, (error, redirectLocation, props) => {
});
我的最终解决方案是将
'/admin'
添加到match()方法中的location
属性:
match({
routes,
location: '/admin' + req.url
}, (error, redirectLocation, props) => {
});