The routing configuration is as follows:
import React from 'react';
import ReactDom from 'react-dom';
import Index from './index';
import {Router,Route, hashHistory} from 'react-router';
import ComponentList from './components/list';
export default class Root extends React.Component{
render(){
return (
<Router history={hashHistory}>
<Route component={Index} path="/" />
<Route component={ComponentList} path="/list" />
</Router>
);
}
}
ReactDom.render(<Root/>,document.getElementById('example'));
Start the project with webpack-dev-server,
Enter http://localhost:8080/# and http://localhost:8080/ both display index,
Enter http://localhost:8080/ list prompts Cannot GET /list,
http://localhost:8080/#/list also displays index, but the list is not displayed. Any solution? ? ? ? ? ?
某草草2017-05-19 10:12:34
history changed to browserHistory
render(){
return (
<Router history={browserHistory}>
<Route component={Index} path="/" />
<Route component={ComponentList} path="/list" />
</Router>
);
}
Then check whether your ComponentList is written correctly
import React from 'react'
export default class ComponentList extends React.Component {
render() {
return(
// your code
)
}
}