React路由器将查询附加到URL [英] React router appending query to URL

查看:55
本文介绍了React路由器将查询附加到URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

React路由器似乎将查询附加到我的路由末尾。该应用程序由运行express的节点服务器提供服务。我正在使用最新版本的react-router1.0.0-rc1

React router seems to be appending a query to the end of my routes. The app is being served by a node server running express. I'm using the latest version of react-router "1.0.0-rc1"

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

两个问题

1 )为什么会发生这种情况?

1) Why is this happening?

2)如何阻止它将查询附加到网址?

2) How can I stop it from appending the query to the url?

这是我到目前为止的代码:

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);


推荐答案

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


HTML5为我们提供了pushState方法和popstate事件,但在
旧浏览器中,我们唯一拥有的是URL。因此,当使用hash
历史记录时,您会在查询字符串中看到一个额外的项目,看起来像
类似于_k = 123abc。这是历史记录用于在页面加载之间的window.sessionStorage中查找
持久状态数据的键。

HTML5 gives us the pushState method and the popstate event, but in older browsers the only thing we have is the URL. So, when using hash history, you'll see an extra item in your query string that looks something like _k=123abc. This is a key that history uses to look up persistent state data in window.sessionStorage between page loads.

你可以检查上面的链接和这个链接,了解如何阻止它,如果你不喜欢它: https://github.com/rackt/react-router/issues/1952#issuecomment-140401701

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

这篇关于React路由器将查询附加到URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆