Sometimes when a user try to leave a page we may like to inform that he has unfinished task. In order to do that we can use the Prompt component. The Prompt component takes two props which are when and message(<Promptwhen ={true?'Happy':'Sad'}message ='When even I am happy'/>). Let's implement this in the previous code.
In the following code a Prompt has been implemented without when therefore it will check all the routes.
Instead of without condition, let's inform the user if he really wants to log out.
Instead of without condition, let's inform the user if he really wants to log out by adding checking some condition using a call back function inside the message.