重定向到指定的 URL

5年以前  |  阅读数:365 次  |  编程语言:JavaScript 

重定向到指定的 URL。

使用window.location.hrefwindow.location.replace()重定向到url。传递第二个参数以模拟链接单击 (true-默认值) 或 HTTP 重定向 (false).

const redirect = (url, asLink = true) =>
asLink ? window.location.href = url : window.location.replace(url);
// redirect('https://google.com')

Copyright© 2013-2020

All Rights Reserved 京ICP备2023019179号-8