Reactjs 在IONAL-4 react中自动导航到所需页面
我有一个页面,上面写着输入你的邮件id以更改密码,在输入邮件id并点击提交按钮时,我希望用户重定向到另一个页面,直到现在,对于导航,我一直在做类似这样的事情Reactjs 在IONAL-4 react中自动导航到所需页面,reactjs,ionic-framework,ionic4,ionic-react,Reactjs,Ionic Framework,Ionic4,Ionic React,我有一个页面,上面写着输入你的邮件id以更改密码,在输入邮件id并点击提交按钮时,我希望用户重定向到另一个页面,直到现在,对于导航,我一直在做类似这样的事情 const redirect = useCallback(() => navigate("/login"), [navigate]); redirect() 但它们似乎只能在功能组件中使用,我想在使用redux时重定向action creater中的用户 这是我的密码 const ForgotPassword:
const redirect = useCallback(() => navigate("/login"), [navigate]);
redirect()
但它们似乎只能在功能组件中使用,我想在使用redux时重定向action creater中的用户
这是我的密码
const ForgotPassword: React.FC<Props> = (props) => {
const {
register,
handleSubmit,
errors,
control,
setValue,
getValues,
} = useForm();
const { navigate } = useContext(NavContext);
const [email, setEmail] = useState("");
const dispatch = useDispatch();
const modal = useSelector((state: RootState) => {
return { modal: state.modal };
});
const error = useSelector((state: RootState) => {
return { error: state.error.iserror };
});
const onSubmit = (data: any) => {
console.log(errors.keys);
console.log(data);
dispatch(changePassword(data.email));
};
const redirect = useCallback(() => navigate("/set-password"), [navigate]);
return (
<div>
<Layout title={"Forgot Password"} backButton={false} backHref={""} />
<IonContent>
<div className="forgot-content">
<form onSubmit={handleSubmit(onSubmit)}>
<IonItem>
<IonLabel position="stacked" className="otpMail">
Email
</IonLabel>
<Controller
render={({ onChange, onBlur, value }) => (
<IonInput
placeholder="Enter your email"
onIonChange={onChange}
/>
)}
control={control}
name="email"
defaultValue=""
rules={{
required: true,
pattern: {
value: /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i,
message: "Error",
},
}}
/>
{_.get("email.type", errors) === "required" && (
<p className="errorWarning">This field is required</p>
)}
{_.get("email.type", errors) === "pattern" && (
<p className="errorWarning">Email address is not valid</p>
)}
</IonItem>
<div className="verifyButton">
<IonButton type="submit" expand="block">
Get OTP
</IonButton>
</div>
</form>
</div>
</IonContent>
</div>
);
};
export default ForgotPassword;
App.tsx
const App: React.FC = () => (
<IonApp>
<IonReactRouter>
<IonRouterOutlet id="menu">
<Route path="/signup" component={Signup} exact={true} />
<Route path="/" component={Home} exact={true} />
<Route path="/verify" component={Verify} exact={true} />
<Route path="/login" component={Login} exact={true} />
<Route
path="/forgot-password"
component={forgotPassword}
exact={true}
/>
<Route path="/set-password" component={setPassword} exact={true} />
</IonRouterOutlet>
</IonReactRouter>
</IonApp>
);
export default App;
const-App:React.FC=()=>(
);
导出默认应用程序;
Index.tsx
ReactDOM.render(
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
<App />
</PersistGate>
</Provider>,
document.getElementById("root")
);
ReactDOM.render(
,
document.getElementById(“根”)
);
ReactDOM.render(
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
<App />
</PersistGate>
</Provider>,
document.getElementById("root")
);