我有以下index.html。 我正在尝试使用路由器。
foo<int, aClass, true>( iterator );
我收到以下错误:如何克服这个
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Twitter API</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react-dom.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.21.1/babel.min.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-router-dom/4.2.2/react-router-dom.min.js"></script>
</head>
<body>
<div id="root"></div>
<script type="text/babel">
class Module extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<div>
<p>This is Module</p>
</div>
);
}
}
class Basic extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<ReactRouterDOM.Router>
<ReactRouterDOM.Route exact path="/" component={Module} />
</ReactRouterDOM.Router>
)
}
}
ReactDOM.render(
<Basic />,
document.getElementById('root')
);
</script>
</body>
</html>
答案 0 :(得分:0)
您需要使用BrowserRouter
,如果您的网页未从根目录运行,则需要设置basename
属性(并且您要使用/
路径)
<ReactRouterDOM.BrowserRouter basename="/~user/">
<ReactRouterDOM.Route exact path="/" component={Module} />
</ReactRouterDOM.BrowserRouter>