简体   繁体   English

当我单击注销按钮时,会打开确认警报。 当我取消时,它将重定向登录页面,但我想重定向当前页面。 我该怎么做?

[英]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.

相关问题 单击浏览器的后退按钮时如何在主页上重定向 - how can i redirect on the home page when i click on browser's back button 单击复选框时如何禁用页面重定向? - How I can disable page redirect when click on checkbox? 我希望我的 html 页面在我提交某个输入时重定向到另一个 html 页面我该怎么做 - I want my html page to redirect to another html page when I submit a certain input how can i do that 无法将我的表单重定向到新的 html 页面。 它会转到 localhost:3000/confirm.html 而我希望它在新窗口中打开 confirm.html - Unable to redirect my form to a new html page. Its going to localhost:3000/confirm.html instead i want it to open confirm.html in a new window 如何在 React js 中将登录重定向到当前页面? - How can I redirect login to current page in react js? 当用户单击注销并重定向到主页时,我想加载一个gif图像。 我正在尝试使用php - I want to load a gif image when user clicks on logout and then redirects to home page. i am trying to do using php 如何在Laravel中重定向到当前页面 - How do I redirect to current page in laravel 单击按钮时如何重定向到我的网站? - How can I redirect to my website when I click a button? 我想在单击按钮时重定向到同一目录的下一页 - - I want to redirect on next page on same directory on button click - 如何通过打开新窗口执行OAuth请求,而不是从当前页面重定向用户? - How can I do OAuth request by open new window, instead of redirect user from current page?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM