簡歷:我需要運行React路由器沒有wepback或類似的工具。直接從CDN鏈接,但我堅持一些require.js錯誤。使用React路由器與CDN和沒有webpack或瀏覽器
我開始用React構建我的第一個應用程序,並且我正在努力使用React路由器。
HTML:
<body>
<div id="container"></div>
<script src="https://unpkg.com/[email protected]/dist/react.js"></script>
<script src="https://unpkg.com/[email protected]/dist/react-dom.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.23/browser.js"></script>
<script src="https://npmcdn.com/[email protected]/umd/ReactRouter.js"></script>
<script type="text/babel" src="assets/scripts/03_templates/app.js" charset="utf-8"></script>
</body>
JS:
var { Router, Route, IndexRoute, hashHistory, IndexLink, Link, browserHistory } = ReactRouter;
//some classes
ReactDOM.render((
<Router history={hashHistory}>
<Route path="/" component={Window}>
<IndexRoute component={InitialPage}/>
<Route path="register" component={Register} />
<Route path="search" component={Search} />
</Route>
</Router>
), document.getElementById("container"));
一切都運行良好,但我得到這個在控制檯上:
react.js:3639 Warning: You are manually calling a React.PropTypes validation function for the
getComponent
prop onIndexRoute
. This is deprecated and will not work in production with the next major version. You may be seeing this warning due to a third-party PropTypes library.
所以,我想我的反應路由器是一個老版。我改變了鏈接
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-router/4.0.0-0/react-router.js"></script>
Warning: React.createElement: type should not be null, undefined, boolean, or number. It should be a string (for DOM elements) or a ReactClass (for composite components).
我搜索一下它,它似乎問題是1號線。所以我改變了這一點:
var { Router, Route, IndexRoute, hashHistory, IndexLink, Link, browserHistory } = ReactRouter;
要這樣:
import { Router, Route, IndexRoute, hashHistory, IndexLink, Link, browserHistory } from 'react-router';
現在我有這個問題:
app.js:2 Uncaught ReferenceError: require is not defined
我搜索了require.js,嘗試了一些東西,但沒有解決我的問題。我錯過了什麼?我需要運行這個沒有webpack或similars工具。
感謝
我試過類似的4.0.0和沒有工作。所以很容易沒有3.0.0非常感謝你! –