努力讓React-Router爲SPA工作,但我似乎無法讓它呈現除App組件之外的任何東西。ReactJS路由器不路由
import React from 'react';
import ReactDOM from 'react-dom';
import { Router, Route, Link, IndexRoute, browserHistory } from 'react-router';
import Parameter from './components/parameter/Parameter';
class App extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<div className="container">
<h1>TEST</h1>
<Link to="/parameter">Click Me!</Link>
</div>
)
}
}
class Test extends React.Component {
render() {
return (
<div className="container">
<h1>TEST PAGE</h1>
</div>
)
}
}
var routes = (
<Route name="root" component={App} path="/">
<Route component={Test} path="test" />
<Route component={Parameter} path="parameter" />
</Route>
)
ReactDOM.render((
<Router history={browserHistory} routes={routes} />
), document.getElementById('react'))
什麼版本的react-router? –
「react-router」:「^ 3.0.2」 – greyfox
您是否嘗試爲'/ test'和'/ parameter'添加'/'? –