简体   繁体   English

React路由器将查询附加到URL

[英]React router appending query to URL

React router seems to be appending a query to the end of my routes. React路由器似乎将查询附加到我的路由末尾。 The app is being served by a node server running express. 该应用程序由运行express的节点服务器提供服务。 I'm using the latest version of react-router "1.0.0-rc1" 我正在使用最新版本的react-router“1.0.0-rc1”

Example: http://localhost:8080/#/users?_k=8wsy62 示例: http://localhost:8080/#/users?_k=8wsy62

Two questions 两个问题

1) Why is this happening? 1)为什么会这样?

2) How can I stop it from appending the query to the url? 2)如何阻止它将查询附加到网址?

Here is the code I have so far: 这是我到目前为止的代码:

var React = require('react');
var ReactRouter = require('react-router');
var Router = ReactRouter.Router;
var Route = ReactRouter.Route;
var Link = ReactRouter.Link;
var IndexRoute = ReactRouter.IndexRoute;

var App = React.createClass({
    render: function() {
        return (
            <div className="app">
                <h1>App</h1>
                <Link to="/users">Users</Link>
                {this.props.children}
            </div>
        );
    }
});

var Home = React.createClass({
    render: function() {
        return (
            <div className="home">
                <h2>Home</h2>
            </div>
        );
    }
});

var Users = React.createClass({
    render: function() {
        return (
            <div className="users">
                <h2>Users</h2>
            </div>
        );
    }
});

React.render((
    <Router>
        <Route path="/" component={App}>
            <IndexRoute component={Home} />
            <Route path="users" component={Users} />
        </Route>
    </Router>
), document.body);

Taken from this link: http://rackt.github.io/history/stable/HashHistoryCaveats.html 取自此链接: http//rackt.github.io/history/stable/HashHistoryCaveats.html

HTML5 gives us the pushState method and the popstate event, but in older browsers the only thing we have is the URL. HTML5为我们提供了pushState方法和popstate事件,但在旧版浏览器中,我们唯一拥有的是URL。 So, when using hash history, you'll see an extra item in your query string that looks something like _k=123abc. 因此,在使用哈希历史记录时,您会在查询字符串中看到类似_k = 123abc的额外项目。 This is a key that history uses to look up persistent state data in window.sessionStorage between page loads. 这是历史记录用于在页面加载之间的window.sessionStorage中查找持久状态数据的键。

You can check both the link above and this one for ideas on how to stop this if you don't like it: https://github.com/rackt/react-router/issues/1952#issuecomment-140401701 你可以查看上面的链接和这个链接,了解如何阻止它,如果你不喜欢它: https//github.com/rackt/react-router/issues/1952#issuecomment-140401701

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM