Detect Route Change with react-router

前端 未结 8 1016
南笙
南笙 2020-11-27 11:18

I have to implement some business logic depending on browsing history.

What I want to do is something like this:

reactRouter.onUrlChange(url => {
         


        
8条回答
  •  旧巷少年郎
    2020-11-27 11:56

    React Router V5

    If you want the pathName as a string ('/' or 'users'), you can use the following:

      // React Hooks: React Router DOM
      let history = useHistory();
      const location = useLocation();
      const pathName = location.pathname;
    

提交回复
热议问题