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>
);