question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How do I prevent leave route?

See original GitHub issue

Thanks for the nimble navigation project. I am considering use navi instead of react-router in next project.

I want to redirect new user with initial password to change_password_page and prevent it leave the page before password changed. I can’t find the impl in navi, can you help to figure out how make it works with navi?

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:11
  • Comments:18

github_iconTop GitHub Comments

6reactions
lukaszromerowiczcommented, Apr 6, 2021

Hi, is there any update on this? It still is an issue.

Edit: One solution that I found working in a React app is to use the history.block function. You can access the history object using the useHistory() hook. Here’s a little snippet:

const history = useHistory();

useEffect(() => {
    history.block(() => {
        if (condition) {
            return "Your prompt message";
        }
    });
}, [condition]);
0reactions
mongriscommented, Apr 7, 2021

Thanks @lukaszromerowicz. I will try it later.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Emergency Exit Routes
OSHA standards require employers to do the following: • Keep exit routes free of explosive or highly flammable furnishings and other decorations. •...
Read more >
How to prevent route change using react-router - Stack Overflow
const checkForm = (nextState, replace, cb) => { if (form.IsDirty) { console.log('Leaving so soon?'); // I would like to stay on ...
Read more >
Prevent Navigation in Routing - Pragim Tech
In this article, we will understand prevent the user from navigating away from a page when there are some unsaved changes. Lets open...
Read more >
Prevent from navigating away - Get Help - Vue Forum
Assuming you have are using vue-router? You can use a beforeRouteLeave hook. ... The <confirmDialog> recieves a resolve and reject prop along with ......
Read more >
Controlling Access to or from a Route - Rangle.io
To control whether the user can navigate to or away from a given route, use route guards. For example, we may want some...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found