react-router-navigation-prompt
Advanced tools
Comparing version 1.0.1 to 1.1.0
{ | ||
"name": "react-router-navigation-prompt", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "A replacement component for the react-router `<Prompt/>`. Allows for more flexible dialogs.", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -13,3 +13,3 @@ # React Router <NavigationPrompt/> | ||
IMPORTANT: Currently, this does not confirm navigation to another website. | ||
Note: When NavigationPrompt.props.when is truthy, then confirmation is requested when navigating away. Usually, browsers handle the UX themselves, leading to vanilla alert boxes. Also, many browsers require users to interact with your site before confirming navigation away. | ||
@@ -16,0 +16,0 @@ Motivation: https://github.com/ReactTraining/react-router/issues/4635 |
@@ -26,3 +26,3 @@ import React from 'react'; | ||
super(props); | ||
this.state = {action: null, nextLocation: null, isActive: false}; | ||
this.onBeforeUnload = this.onBeforeUnload.bind(this); | ||
this.onCancel = this.onCancel.bind(this); | ||
@@ -40,6 +40,12 @@ this.onConfirm = this.onConfirm.bind(this); | ||
}); | ||
this.state = {action: null, nextLocation: null, isActive: false}; | ||
} | ||
componentDidMount() { | ||
window.addEventListener('beforeunload', this.onBeforeUnload); | ||
} | ||
componentWillUnmount() { | ||
this.unblock(); | ||
window.removeEventListener('beforeunload', this.onBeforeUnload); | ||
} | ||
@@ -70,2 +76,9 @@ | ||
onBeforeUnload(e) { | ||
if (!this.props.when) return; | ||
const msg = 'Do you want to leave this site?\n\nChanges you made may not be saved.'; | ||
e.returnValue = msg; | ||
return msg; | ||
} | ||
unblock() { | ||
@@ -72,0 +85,0 @@ // Init in constructor(). |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
217305
4670