1
在我的应用程序中,我在不同的页面上有许多表单。如果用户对未保存的表单进行了更改,我希望向用户添加警报通知。 React路由器v4似乎有内置<Promt>
这个功能,但是,我试过把它放在我的App Router
组件和表格内,它返回一个错误ReferenceError: formIsHalfFilledOut is not defined
。如何使用这个正确如何使用react-router v4 Promt
EG:Wihtin form
render() {
return (
<Form className="languageForm" onSubmit={this.handleFormSubmit}>
<SingleInput inputType={'text'} controlFunc={this.handleLanguageChange(language.uniqueId)} content={language.language} placeholder={'Language'} bsSize={null} error={language.errors && language.errors.language}/>
<input type="submit" className="btn btn-primary" value="Save"/>
<Prompt when={formIsHalfFilledOut} message="Are you sure you want to leave?"/>
</Form>
);
}
EG:Within App.jsx
const App = appProps => (
<Router>
<Prompt when={formIsHalfFilledOut} message="Are you sure you want to leave?"/>
<NavBar {...appProps}/>
<Grid className="main-page-container">
<Switch>
<Authenticated exact path="/" component={Home} {...appProps}/>
<Authenticated exact path="/admin/profile_candidate/edit/contact_details" component={ContactDetailsFormContainer} {...appProps}/>
<Authenticated exact path="/admin/profile_candidate/edit/summary" component={SummaryFormContainer} {...appProps}/>
<Route render={function() {
return <p>Page not found</p>;
}}/>
</Switch>
</Grid>
</Router>
);