{"id":8604,"date":"2021-08-25T18:09:54","date_gmt":"2021-08-25T10:09:54","guid":{"rendered":"https:\/\/sdeno.com\/?p=8604"},"modified":"2021-08-25T18:12:20","modified_gmt":"2021-08-25T10:12:20","slug":"%e8%a7%a3%e5%86%b3%ef%bc%9awarning-hash-history-cannot-push-the-same-path-a-new-entry-will-not-be-adde","status":"publish","type":"post","link":"https:\/\/sdeno.com\/?p=8604","title":{"rendered":"\u89e3\u51b3\uff1aWarning: Hash history cannot PUSH the same path; a new entry will not be adde"},"content":{"rendered":"<pre>\/\/link.js\r\nimport React from 'react';\r\nimport {Route, Link as ReactRouterLink} from 'react-router-dom';\r\nimport {createPath} from 'history';\r\n\r\nconst Link = ({to, replace, ...props}) =&gt; (\r\n    &lt;Route path={typeof to === 'string' ? to : createPath(to)} exact&gt;\r\n        {({match}) =&gt; (\r\n            &lt;ReactRouterLink {...props} to={to} replace={replace || !!match} \/&gt;\r\n        )}\r\n    &lt;\/Route&gt;\r\n);\r\n\r\nLink.propTypes = ReactRouterLink.propTypes;\r\nLink.defaultProps = ReactRouterLink.defaultProps;\r\n\r\nexport default Link;<\/pre>\n<p>&nbsp;<\/p>\n<p>\u4f7f\u7528\uff1a<\/p>\n<pre>import Link from '.\/link'; \/\/ use the custom Link component instead of the react-router Link\r\n\r\nconst App = () =&gt; {\r\n    &lt;ul&gt;\r\n        &lt;li&gt;&lt;Link to={{ pathname: '\/one', search: 'foo=bar' }}&gt;one&lt;\/Link&gt;&lt;\/li&gt;\r\n        &lt;li&gt;&lt;Link to=\"\/two\"&gt;two&lt;\/Link&gt;&lt;\/li&gt;\r\n    &lt;\/ul&gt;\r\n}<\/pre>\n<p><a href=\"http:\/\/ask.sov5.cn\/q\/spgFuzIzM3\" target=\"_blank\" rel=\"noopener\">http:\/\/ask.sov5.cn\/q\/spgFuzIzM3<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\/\/link.js import React from &#8216;react&#8217;; import {Route, Lin [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[54],"tags":[],"class_list":["post-8604","post","type-post","status-publish","format-standard","hentry","category-react"],"_links":{"self":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts\/8604","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=8604"}],"version-history":[{"count":0,"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts\/8604\/revisions"}],"wp:attachment":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=8604"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=8604"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=8604"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}