How do you handle navigation prompts or confirmations before leaving a route in React Router v5

0 votes
Can i know How do you handle navigation prompts or confirmations before leaving a route in React Router v5?
23 hours ago in Node-js by Ashutosh
• 27,650 points
17 views

1 answer to this question.

0 votes

Use the <Prompt> component to warn users before leaving a route.

Example:

import { Prompt } from 'react-router-dom';

import { useState } from 'react';

function MyForm() {

  const [isBlocking, setIsBlocking] = useState(false);

  return (

    <>

      <Prompt

        when={isBlocking}

        message="Are you sure you want to leave this page?"

      />

      <input

        onChange={(e) => setIsBlocking(e.target.value.length > 0)}

        placeholder="Type something..."

      />

    </>

  );

}

answered 21 hours ago by anonymous

Related Questions In Node-js

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

How can you programmatically navigate to a different route in React Router v5?

In React Router v5, you can programmatically ...READ MORE

answered 4 days ago in Node-js by anonymous
28 views
0 votes
1 answer
0 votes
1 answer
0 votes
0 answers
0 votes
1 answer

How do you handle scroll restoration in a React-Router app?

By default, React Router does not restore ...READ MORE

answered Feb 24 in Node-js by Kavya
164 views
0 votes
1 answer

How do you handle a large amount of data in React?

Handling Large Amounts of Data in React To ...READ MORE

answered Feb 24 in Node-js by Kavya
143 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP