我使用的反應路由器V4爲一個項目 這裏是我的CDN陣營路由器V4錯誤「未捕獲的ReferenceError:路由器沒有定義」
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react-dom.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-router/4.0.0-alpha.3/react-router.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.38/browser.min.js"></script>
這裏是我的代碼
ReactDOM.render(
<Router>
<Route path="/" component={LoginForm} />
</Router>
,document.getElementById('root'));
</script>
在登錄表單代碼看起來象
var LoginForm = React.createClass({
render: function() {
return (
<div>
<div id="postdiv">
<form id="customerForm" data-toggle="validator">
<div className="form-group">
<span className="label label-default">Login</span>
...
我收到此錯誤
Uncaught ReferenceError: Router is not defined
at eval (eval at n.run (browser.min.js:3), <anonymous>:79:3)
at Function.n.run (browser.min.js:3)
at l (browser.min.js:3)
at i (browser.min.js:3)
您需要的WebPack編譯JSX,然後可以導入反應路由器是這樣的:從「反應路由器」進口{}路由器; – Shota
嘗試使用React Router v4的最新版本https://cdnjs.cloudflare.com/ajax/libs/react-router/4.0.0-beta.5/react-router.min.js – Freez