javascript - react 配置的路由·不管用
为情所困
为情所困 2017-05-19 10:10:34
0
1
539

路由配置如下:
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'));

用webpack-dev-server启动项目,
输入http://localhost:8080/#和http://localhost:8080/都显示index,
输入http://localhost:8080/list提示Cannot GET /list,
http://localhost:8080/#/list也显示index 就是不会显示list 求解??????

为情所困
为情所困

全部回复(1)
某草草

history改browserHistory

render(){
    return (
        <Router history={browserHistory}>
            <Route component={Index} path="/" />
            <Route component={ComponentList} path="/list" />
        </Router>
    );
}

然后看看你的ComponentList 这个写的是否正确

import React from 'react'
export default class ComponentList extends React.Component {
    render() {
        return(
           // your code
        )
  }
}
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板