Reactjs 推送路由以更改url而不重新加载页面

Reactjs 推送路由以更改url而不重新加载页面,reactjs,react-router,Reactjs,React Router,我有一个react应用程序 我的路由看起来像这样=> <AppRoute path="/profile" exact={true} menuTitle="Profile" component={pages.Profile} /> <AppRoute path="/profile/post_feed" exact={true} menuTitle="Post Feed" component={page

我有一个react应用程序

我的路由看起来像这样=>

<AppRoute path="/profile" exact={true} menuTitle="Profile" component={pages.Profile} />
<AppRoute path="/profile/post_feed" exact={true} menuTitle="Post Feed" component={pages.PostFeed} />
<AppRoute path="/profile/story_feed" exact={true} menuTitle="Story Feed" component={pages.StoryFeed} />
但这会触发页面的完全刷新。。。以及所有关联的查询。我在我的
Profile
组件(从路由调用的组件)中添加了以下效果


这个触发器在加载时,然后对于每个过滤器,页面被完全刷新。但是我希望这些东西触发一次,当路由没有改变(只有查询参数)时,这些效果不会被重新触发。可能吗?

试着用替换而不是推

    const setQueryParams = (filterId: number | null) => {

        history.replace({ search: `?filterId=${filterId}` })// CHANGE HERE
    };



  const handleFilterSelectionChange = (id: number) => {
      setQueryParams(id);
    //....
  };

尝试使用替换而不是推

    const setQueryParams = (filterId: number | null) => {

        history.replace({ search: `?filterId=${filterId}` })// CHANGE HERE
    };



  const handleFilterSelectionChange = (id: number) => {
      setQueryParams(id);
    //....
  };

您可以使用shouldComponentUpdate或直接推送到窗口历史记录。我有一个类似于google maps的应用程序,我经常更新URL,我直接使用窗口历史记录进行更新,我知道我不想重新渲染。您可以使用shouldComponentUpdate或直接推送到窗口历史记录。我有一个类似于google maps的应用程序,我经常更新URL,并且我直接使用窗口历史记录进行更新,我知道我不想重新呈现。这与推送T的操作相同。T对不起,我忘记了相关的详细信息,现在检查它。它仍然会重新加载页面。那我的密码里肯定有什么东西。这个解决方案对你有用吗?调试ahah真的很烦人,只是删除
history.replace({search:urlParams.search})做的技巧,但idk为什么它重新加载我的路线,如果我把它放回。是的,这个解决方案适合我。“放回去”你的意思是,goBack()到路由?它的作用与推T相同。T抱歉,我忘记了一个相关的细节,现在检查它。它仍然会重新加载页面。那我的密码里肯定有什么东西。这个解决方案对你有用吗?调试ahah真的很烦人,只是删除
history.replace({search:urlParams.search})做的技巧,但idk为什么它重新加载我的路线,如果我把它放回。是的,这个解决方案适合我。“把它放回去”是指goBack()到路线?
    const setQueryParams = (filterId: number | null) => {

        history.replace({ search: `?filterId=${filterId}` })// CHANGE HERE
    };



  const handleFilterSelectionChange = (id: number) => {
      setQueryParams(id);
    //....
  };