#Navigation inside hook

4 messages · Page 1 of 1 (latest)

fast hatch
#

Can we navigate route inside (afterChangeHook) ?
I want to create a collection and after create use hook (afterChangeHook) and inside this hook, I wish to change route after create collection or redirect another collection.

lament summit
#

@fast hatch Were you able to find an answer?
You can't use afterChangeHook as that is going to be run server side. Instead you'll need a custom field UI component or add a custom provider to your admin UI that handles it instead.

#

I'm not sure how familiar you are with react.
Routing is all done with:
import { useHistory } from 'react-router-dom';
In your component you can use push
const { push } = useHistory();

Then in a useEffect() you will need to figure out what info you can get to compare to know if your condition is met to then call the redirect.

fast hatch
#

@Dan thanks to you for your great time
I have already test using custom field. But I want to navigation after form submit I think we can't get react-router-dom or react hooks inside payloadHooks therefor it not work for us