Express将覆盖react-router客户端路由

我不想使用服务器端渲染,因为这是一个绝对痛苦的工作,我已经得到了一切工作没有它。

但是,如果我做一个新的url/test并访问本地主机:3000 /testing我得到Cannot get /test

这就是我的索引页面被提供

 app.get("/", function(req, res) { res.sendFile(__dirname + '/client/index.html') }) 

路线文件

 const routes = ( <div> <Route path="/" component={ AppContainer }> <IndexRoute component={ RegistrationContainer }/> <Route path="test" component={ StripeContainer }/> </Route> </div> ) export default routes 

我现在正在处理这个问题,我想你需要在React路由之前声明/testpath。

我将如何在我的应用程序中实现它是在Express中声明一些用于用户login的路由,然后在最后发送其他任何内容到React。

就像是

 app.get('/login', function(...)); app.get('/logout', function(...)); app.get('*', <TO-REACT>); 

我不确定这是否是处理这个问题的正确方法,但它应该起作用。

让我知道它是如何工作的,或者如果你预见到使用这个问题的任何问题。

更新:我可以证实,这现在正在为我工​​作。 这里是我的快递路线文件和基本的React文件的缩写版本。

路线

 // redirects any requests to root of domain to React (a polling app) app.get('/', function(req, res) { res.redirect('/polls'); }); // authentication routes app.get('/login' function(....)); app.get('/logout' function(....)); app.get('/login/callback' function(....)); app.get('/login/authorise' function(....)); // React catch all route app.get('*', function(....{sendfile....}); 

基地反应文件

 import React from 'react'; import ReactDOM from 'react-dom'; import {Router, Route, Redirect, browserHistory} from 'react-router'; const PollListScreen = require('./PollListScreen.js'); const PollAdd = require('./PollAdd.js'); ReactDOM.render( ( <Router history={browserHistory}> <Route path='/polls' component={PollListScreen} /> <Route path='/polls/new' component={PollAdd} /> </Router> ), document.getElementById('app') );