javascript - react 配置的路由·不管用
为情所困
为情所困 2017-05-19 10:10:34
[JavaScript讨论组]

路由配置如下:
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
        )
  }
}
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号