javascript - React configured routing·doesn't work
为情所困
为情所困 2017-05-19 10:10:34
0
1
519

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? ? ? ? ? ?

为情所困
为情所困

reply all(1)
某草草

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
        )
  }
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template