这是App.js -这很好
<Route path='/page1'>
<Page1 />
</Route>
this is "/page1">
var location = window.location.href
<Link to="/page1/2">
<p>Click to change</p>
</Link>
如果我点击它paragraf改变url/page1/2但var位置仍然不是改变了/所述 -------------------------------------------------------------------------------------------------------------------- 我想要当url转变var位置到新位置(window.location.href) (/page1/2)
//或者我只需要告诉我如何"on url "做点什么,比如alert('url changed')或者console.log('url changed')
如果你使用的是react-router,使用useLocation
hook获取路径
import React from "react";
import { useLocation } from "react-router-dom";
export const App = () => {
let location = useLocation();
return <div>...</div>;
}