[英]When i click in logout button open a confirm alert. When i cancel it will redirect login page but i want to redirect current page. How i can do it?
In My react application.在我的反应应用程序中。 When i click logout button.
当我单击注销按钮时。 it open a confirm alert.
它打开确认警报。 if i confirm it i will logout from my application.
如果我确认,我将从我的应用程序注销。 whenever i cancel it it also redirect to my login route.
每当我取消它时,它也会重定向到我的登录路径。 I want the route will be the same when i will cancel it.
我希望取消路线时路线相同。 How can i do it?
我该怎么做? My code is:
我的代码是:
Code Screenshot Client Site Screenshot代码截图客户端截图
const logOut = () => {
const confirm = window.confirm('Are you sure to logout?');
if (confirm) {
signOut(auth)
}
} }
You can add else
statement for the required purpose.您可以为所需目的添加
else
语句。 Following code demonstrate the purpose:以下代码演示了目的:
const logout = () => {
const confirm = window.confirm("are you sure?");
if(confirm){
window.location.href = "http://www.w3schools.com";
}else {
// same as clicking a link
// not optimal solution though
window.location.href = window.location.href;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.