在有人向我推荐其他答案之前-我已经搜索并尝试了所有答案。基本上,我使用Laravel设置了我的第一个React项目,并试图使其将Example.js
文件内容注入到welcome.blade.php
文件中,但是每次加载页面时,控制台中都会出现以下错误和一个空白页:
Uncaught TypeError: Cannot read property 'func' of undefined
at Object.exports.__esModule (app.js:667)
at __webpack_require__ (app.js:20)
at Object.exports.__esModule (app.js:1598)
at __webpack_require__ (app.js:20)
at Object.exports.__esModule (app.js:15798)
at __webpack_require__ (app.js:20)
at Object.<anonymous> (app.js:17269)
at __webpack_require__ (app.js:20)
at Object.defineProperty.value (app.js:17255)
at __webpack_require__ (app.js:20)
我进行了研究,发现大多数人说这是一个React-router问题,已在3.2.0版中解决,但是这里不是这种情况,因为我正在使用该版本。我的yarn.lock文件:
react-router@^3.2.0:
version "3.2.1"
resolved "https://registry.yarnpkg.com/react-router/-/react-router-3.2.1.tgz#b9a3279962bdfbe684c8bd0482b81ef288f0f244"
dependencies:
create-react-class "^15.5.1"
history "^3.0.0"
hoist-non-react-statics "^2.3.1"
invariant "^2.2.1"
loose-envify "^1.2.0"
prop-types "^15.5.6"
warning "^3.0.0"
基本上,我所做的只是将Example.vue
文件替换为Example.js
文件,并添加了一些简单的内容,然后在app.js
文件中规定了使用此组件的路由。然后,我的刀片文件将存储“ example” div。
我正在使用Laravel 5.6,React 16和React Router 3.2.0
如果有人能在正确的方向指点我,我将不胜感激,因为我什至无法完成我的项目,甚至还没有可见的示例页面!
编辑:代码示例
app.js:
require('./bootstrap');
import React from 'react';
import { render } from 'react-dom';
import { Router, Route, browserHistory } from 'react-router';
import Example from './components/Example';
render(
<Router history={browserHistory}>
<Route path="/" component={Example} >
</Route>
</Router>,
document.getElementById('example'));
Example.js:
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
class Example extends Component {
render() {
return (
<div>
<h1>Cool, it's working</h1>
</div>
);
}
}
export default Example;
if (document.getElementById('example')) {
ReactDOM.render(<Example />, document.getElementById('example'));
}
welcome.blade.php:
<!doctype html>
<html lang="{{ app()->getLocale() }}">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Laravel</title>
<link href="{{asset('css/app.css')}}" rel="stylesheet" type="text/css">
</head>
<body>
<div id="example"></div>
<script src="{{asset('js/app.js')}}" ></script>
</body>
</html>
答案 0 :(得分:0)
请使用react-router
代替react-router-dom
。
如果没有帮助,请通知我。