可以通过传递 window.location 或原始 URL goole.com?search=easy&page=3 从 url 轻松检索查询参数。
const getParameters = (URL) => {
URL = JSON.parse('{"' + decodeURI(URL.split("?")[1])
.replace(/"/g, '\\"').replace(/&/g, '","')
.replace(/=/g, '":"') +'"}');
return JSON.stringify(URL);
};
getParameters(window.location)
// Result: { search : "easy", page : 3 }