比如说,我有 2 个页面,localhost 和 localhost/test,在 localhost 上有一个链接,指向 localhost/test。
localhost/test 可以通过点击链接访问,但是刷新或者手动输入 url localhost/test 时会返回
Not Found
The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.
我的代码是这样的:
import React from 'react';
import ReactDOM from 'react-dom';
import { Router, Route, IndexRoute, Link, IndexLink, browserHistory } from 'react-router';
import session from 'express-session';
import $ from 'jquery';
const App = React.createClass ({
render() {
return (
<div>
Router lza.
<ul>
<li><Link to="test">Test</Link></li>
</ul>
</div>
);
}
})
const App2 = React.createClass ({
render() {
return (<div>Router lza.aasss</div>);
}
})
var routes = (
<Router history={browserHistory}>
<Route path="/">
<IndexRoute component={App} />
<Route path="/test" component={App2} />
</Route>
</Router>
)
ReactDOM.render(routes, document.getElementById("hello"))
如何解决?
我试图通过 express 4 解决它,但是当我从“express”导入 express 时,它会报告
Uncaught TypeError: Cannot read property 'prototype' of undefined
因此我尝试了 express-session,但我找不到如何使用它的完整示例。许多示例都有一个名为“app”的变量,但它是如何定义的?或者请告诉我如何使刷新时可以访问网址。谢谢你。