Home > Enterprise >  how to redirect from axios in react native & pass data to the route
how to redirect from axios in react native & pass data to the route

Time:12-13

i have a axios in react native when post method is success i want to go to /home route and pass data56 to home route

    axios
      .post('http://10.0.2.2:8000/api/details', Data56)

      .then(() => {
       
        window.location.href = '/Home';
      })

what i am trying to do is make a session in home route it will be better if i can access data sutable for creating session in /home route

CodePudding user response:

Instead of using route, why don't you just use something like this navigation.navigate("ScreenName", {data: Data56})

Here's the example:

      axios
        .post('http://10.0.2.2:8000/api/details', Data56)

        .then((res) => {
          navigation.navigate('ScreenName', { data: res.data });
        });

On the Screen component:


const Screen = ({
  navigation,
  route,
}) => {
  const data = route.params.data;

...
  • Related