重定向到URL
重定向到指定的URL。
- 使用
Window.location.href或Window.location.replace()将页面重定向到url。 - 传递第二个参数以模拟链接点击(
true- 默认)或HTTP重定向(false)。
const redirect = (url, asLink = true) =>
asLink ? (window.location.href = url) : window.location.replace(url);
redirect('https://google.com');