I am relatively new to reacts and I'm trying to figure out how to get React router to work. I've got a super simple test app that looks like this:
import React from 'react';
import ReactDOM from 'react-dom';
import {BrowserRouter as Router, Route, Switch, IndexRoute, Link} from 'react-router-dom';
const Home = () => <h1><Link to= "/about">Click Me</Link></h1>
const About = () => <h1>About Us</h1>
const Test = () => (
<Router>
<Switch>
<Route path ="/" component = {Home} />
<Route path ="/about" component = {About} />
</Switch>
</Router>
)
ReactDOM.render(<Test />, document.getElementById('app'));
when I run the app the home component loads without any trouble, and when I click the "Click Me" link the url changes to localhost/about, however nothing happens. If I click refresh I get a "Cannot GET /about." Clearly I am doing something wrong but I haven't been able to figure out what. I am also using Webpack.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…