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.

Custom notification dialogue/modal for setRouteLeaveHook?

See original GitHub issue

Hi,

I couldnt find any information online regarding this and the docs only show mention of window.confirm. Is it possible to set a custom notification for routeLeaveHook instead of using window.confirm. I created a stackoverflow question regarding this and my particular use case for it in more detail and would like to know if this is currently possible or whether there is a specific reason why we cannot do this and whether this could be something implemented. I have a code example of how I would like to use it inside the question.

Im using react-router 2.0

http://stackoverflow.com/questions/35770438/show-custom-dialog-setrouteleavehook-or-history-listenbefore-react-router-redux

What this feature means for your product. Currently the window.confirm dialog is quite clunky and doesnt fit into the UX and design for the site.

What will it allow you to do that you can’t do today? It will allow us to provide different means to transition from one route to the next in terms of both UI and UX.

How will it make current work-arounds straightforward? While @DanielSWolf provided a possible solution to me it feels that something like this should be built into the framework since in my opinion will become a fairly common requirement that setRouterLeaveHook should allow for since it feels like a variant on the same functionality (synchronous vs asynchronous).

What potential bugs and edge cases does it help to avoid? As mentioned above it not aboout avoiding bugs but rather expanding on the functionality of setRouterLeaveHook to accept an async flow. While this can be done via @DanielSWolf solution its seems like this is something that should be baked into the functionality that is already there since its just a variation of what one might require.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:14
  • Comments:20 (7 by maintainers)

github_iconTop GitHub Comments

14reactions
knowbodycommented, Mar 4, 2016

Please follow the issue template, @taion closed the issue as it didn’t follow the template.

6reactions
oztunecommented, Mar 23, 2016

@taion Thanks for clarifying. For anyone trying to do this but getting lost in the labyrinth of documentation, here’s how I did it:

// make sure to npm install history
import { createHistory, useBeforeUnload } from 'history'
import { Router, useRouterHistory } from 'react-router'

const myBrowserHistory = useBeforeUnload(useRouterHistory(createHistory))()

<Router history={ myBrowserHistory } routes={ routes } />

Now if you return a string from your setRouteLeaveHook callback, it will be used for both soft transitions (those using the HTML5 API) and hard transitions (navigating to a different domain or refreshing the page).

Overall I really like the API, but it would be awesome if this explanation was in https://github.com/reactjs/react-router/blob/master/docs/guides/ConfirmingNavigation.md

Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom notification dialogue/modal for setRouteLeaveHook?
Hi, I couldnt find any information online regarding this and the docs only show mention of window.confirm. Is it possible to set a...
Read more >
Confirming navigation with with custom dialog using ...
When you call createHistory , one of the options to it is getUserConfirmation , which takes a prompt message and a callback ....
Read more >
Javascript – Confirming navigation with with custom dialog ...
Javascript – Confirming navigation with with custom dialog using setRouteLeaveHook · Notification.js · ModalConfirmation.js · createConfirmationHistory.js · index.
Read more >
Using React-Router v4/v5 Prompt with custom modal component
With React-Router v4, we can easily insert route blocking logic into any scene using Prompt, passing only two props: when and message.
Read more >
Build Your Own Confirm Dialog & Notification Material UI
Build Confirm Dialog & Notification with React Material UI.In this react material UI tutorial, we discuss how to create custom confirm ...
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