【发布时间】:2015-12-16 22:27:58
【问题描述】:
看起来很奇怪,当我打开/时,浏览器会在地址中显示/#/?_k=dlo2cz之类的东西。每次刷新页面或切换到其他路由时,随机查询字符串值都会发生变化。
代码被复制粘贴到react-router分支1.0.0-rc1。
import React from 'react';
import { Router, Route, Link, IndexRoute } from 'react-router';
const App = React.createClass({
render() {
return (
<div>
<h1>App</h1>
{/* change the <a>s to <Links>s */}
<ul>
<li><Link to="/about">About</Link></li>
<li><Link to="/inbox">Inbox</Link></li>
</ul>
{/*
next we replace `<Child>` with `this.props.children`
the router will figure out the children for us
*/}
{this.props.children}
</div>
)
}
});
const Message = React.createClass({
render() {
return <h3>Message</h3>
}
});
const About = React.createClass({
render() {
return <h3>About</h3>
}
});
const Inbox = React.createClass({
render() {
return (
<div>
<h2>Inbox</h2>
{/* Render the child route component */}
{this.props.children || "Welcome to your Inbox"}
</div>
)
}
})
// Finally, we render a <Router> with some <Route>s.
// It does all the fancy routing stuff for us.
React.render((
<Router>
<Route path="/" component={App}>
<Route path="about" component={About} />
<Route path="inbox" component={Inbox}>
{/* Add the route, nested where we want the UI to nest */}
<Route path="messages/:id" component={Message} />
</Route>
</Route>
</Router>
), document.body);
【问题讨论】:
标签: reactjs react-router