【问题标题】:React Router issues反应路由器问题
【发布时间】:2017-03-24 01:35:05
【问题描述】:

我正在学习 react-router,但我不使用 Node 作为服务器。我正在做的是将所有文件放在 MacOSX 上 XAMPP 的 /htdocs 中,以前所有代码都很好,直到我添加反应路由器。控制台上的错误是: 未捕获的类型错误:无法读取未定义的属性“getCurrentLocation”。

示例代码如下:

//app.jsx
import React from 'react';
import ReactDOM from 'react-dom';
import { Router, Route, hashHistory, IndexRoute} from 'react-router';
import App from './component/App.jsx';
import Home from './component/Home.jsx';
import Repos from './component/Repos.jsx';
import About from './component/About.jsx';
ReactDOM.render(
    <Router>
        <Route path="/" component={App}>
            <IndexRoute component={Home}/>
            <Route path="/repos/:name" component={Repos} />
            <Route path="/about" component={About} />
    </Route>
</Router>,
document.getElementById('app')
);

这是我的 webpack 配置

var config = {
    entry: './index.jsx',
    output: {
    path: './',
    filename: 'index.js'
},
module: {
    loaders: [
             {
        test: /\.jsx?$/,
        exclude: /node_modules/,
        loader: 'babel',

        query: {
           presets: ['es2015', 'react']
        }
        }
    ]
}
}
module.exports = config;

渲染导入的任何单个组件都没有问题,只是简单的静态组件,我在这里展示其中一个:

//Home.jsx
import React from 'react';
const Home = () => (
  <div>Home</div>
);
export default Home;

谁能帮我解决这个问题?

【问题讨论】:

    标签: reactjs server react-router


    【解决方案1】:

    更改为:

    <Router history={browserHistory}>
    

    为我工作。

    【讨论】:

      猜你喜欢
      • 2020-12-21
      • 1970-01-01
      • 2021-11-25
      • 2018-07-07
      • 2021-02-21
      • 2017-11-06
      • 1970-01-01
      • 2022-10-14
      • 1970-01-01
      相关资源
      最近更新 更多