反応する方法
import {useHistory} from 'react-router-dom'
UseHistoryは反応でリダイレクトするものでした.しかし、反応ルータDOM V 6で、それは変わりました.
import {useNavigate} from 'react-router-dom'
const navigate = useNavigate();
const handleSubmit = (e) => {
e.preventDefault()
// some codes..
fetch('http://localhost:8000/notes', {
method: 'POST',
header: {'Content-Type': 'application/json'},
body: JSON.stringify({title, details, category}),
}).then(() => navigate('/')) // navigate() here! redirect to '/'
}
Reference
この問題について(反応する方法), 我々は、より多くの情報をここで見つけました https://dev.to/artemismars/material-ui-how-to-redirect-52diテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol