我已经设置了react-router
版本 4的 React。当我直接在浏览器上输入 URL 时,路由工作,但是当我点击链接时,浏览器上的 URL 会发生变化(例如http://localhost:8080/categories),但是内容不会更新(但如果我刷新,它会更新)。
下面是我的设置:
该Routes.js设置如下:
import { Switch, Route } from 'react-router-dom';
import React from 'react';
// Components
import Categories from './containers/videos/Categories';
import Videos from './containers/videos/Videos';
import Home from './components/Home';
const routes = () => (
<Switch>
<Route exact path="/" component={Home}/>
<Route path="/videos" component={Videos}/>
<Route path="/categories" component={Categories}/>
</Switch>
);
export default routes;
我在Nav.js中使用的链接如下:
<Link to="/videos">Videos</Link>
<Link to="/categories">Categories</Link>
该App.js如下:
import React from 'react';
import './app.scss';
import Routes from './../routes';
import Nav from './Nav';
class AppComponent extends React.Component {
render() {
return (
<div className="index">
<Nav />
<div className="container">
<Routes />
</div>
</div>
);
}
}
AppComponent.defaultProps = {
};
export default AppComponent;