React Router - 路由无法使用浏览器历史记录

时间:2016-07-15 07:57:46

标签: reactjs react-router

我正在为我的SPA使用react路由器,因为我看到哈希路由不适合生产我决定使用浏览器历史记录。但是将其更改为浏览器历史记录,路由无法正常工作。有什么我做错了吗?我的包json有"history": "^2.0.0", "react-router": "^2.5.1",`

            var browserHistory = require('react-router').browserHistory;

            <Router history={browserHistory}>
                <Route path="/" component={PreAuthPage}/>
                <Route path="/loggedIn" component={PostAuthPage}>
                    <Route path="/loggedIn/page1" component={Page1}/>
                    <Route path="/loggedIn/page2" component={Page2}/>
                </Route>
            </Router>`

这是我在客户端和服务器端的内容,我有

          `app.use(express.static(path.join(__dirname,"/app")));

          app.get('*', function (req, res) {
              res.sendFile(path.join(__dirname, '/app', 'index.html'))
           })

`

我应该怎样做才能访问http://localhost:8888/loggedIn

我尝试添加app.get("/loggedIn",...),但没有特定的html页面可以重定向。我已将其添加为组件。

0 个答案:

没有答案