【发布时间】:2018-09-24 21:45:09
【问题描述】:
我正在尝试利用 createMemoryHistory 在不更改 url 地址的情况下移动,因为我的应用程序将在 iframe 内呈现。但是,当我推送到history 时,它似乎更新了我的网址。任何提示将不胜感激!
//history.js
import createMemoryHistory from "history/createMemoryHistory";
const history = createMemoryHistory();
export default history;
//App.js
import history from './history/history';
...
<Router>
<Route
path={'/'}
render={(props) => <Component {...props}/>}
/>
</Router>
//component.js
...
function handleClick(history) {
history.push('somePath'); // this updates my url to be url.com/somePath
}
return (<Button onClick={() => handleClick(this.props.history)}>);
【问题讨论】:
-
你可以试试
createBrowserHistory而不是MemoryHistory -
@RaghavGarg 我刚刚换到
createBrowserHistory,但它仍在更改我的网址:-(
标签: reactjs react-router history