i have a form, so when the user clicks on refresh(ctrl + r, icon on the browser) or close button of the browser. I need to show a custom modal box not the browser prompt box.
in the custom modal box it will show that message "data is going to loss", having two buttons ok and cancel
once the user clicks on the okay it should got home route and cancel it should stay in the page.
i am able to see the browser prompt box for refresh and close, how can i use my custom modal and implement it for the refresh and close actions. Across browser specific.
also the browser prompt message is Changes that you made may not be saved." i am not able to pass custom message and i need okay button and cancel but getting cancel and reload.
See the below implemetation code.
// Form component
import React from 'react'
import CustomPrompt from './Prompt';
import Form from './Form';
const formComponent = (props) => {
return (
<CustomPrompt >
<Form data={props.data}/>
<CustomPrompt />
)
}
export default formComponent
// CustomPrompt
import React, {Component} from 'react';
import {Prompt} from 'react-router-dom';
class CustomPrompt extends Component{
componentWillMount(){
onbeforeunload = e => 'Dont leave'
}
componentWillUnmount(){
onbeforeunload = null
}
render(){
return (
<div>
<Prompt when={true} message={location => location.path('/home')} />
{
this.props.children
}
</div>
)
}
}
export default CustomPrompt;
how can i create a custom modal and override the existing modal of browser on refresh and close.
Any help appreciated :)