Page not found response after fetch() in reactjs

Hello guys,
i am quiet new to webdevelopment and deployed my reactjs app on Netifly. Site name: wondrous-biscotti-4f3540. So basically everything works just fine, except i get a page not found response when doing fetch() requests. Locally everything works just fine, but when i am make a request on my page its responds page not found. I first had this problem too when entering the site, but with the _redirects file and /* /index.html 200 it works. Now only the issue with the fetch is thereā€¦ Can you guys help me? My Repo ist: GitHub - zxmod51/React-Application: React-Application for learning purposes. and the site is: https://bidimdepru.de/ . It would be really awesome when i could get my first ever simple website working :frowning:

Can noone help? Still same problem :frowning:

Hi @zxmod51 , sorry to hear about your problem. Welcome to the Netlify Support Forums by the way.
I took a look at your GitHub repository and it looks like you are using your fetch to get routes to your website instead of an API.

For instance check the code below from your home component. Using the relative url path "/getPosts" will throw an error since it does not exist.

const getPosts = () => {
      const requestOptions = {
          method: 'GET',
          headers: { 'Content-Type': 'application/json' },
      };
      fetch("/getPosts", requestOptions)
      .then(response => {
        if (response.ok) {
          response.json()
          .then(data => {
            setPostItems(data.reverse());
        });
        } else {
          response.text()
          .then(data => {
            console.log(data);
          })
        }     
    })};

Since you are not using fetch to get an API but routes to your website, fetch request gets an HTML. Also once your application is deployed the url path you provided to your fetch is no more valid with regards to your production environment hence the error.

In order for me to help you I would like to find out what you want to achieve by using fetch to get url paths of your site instead of an API?

Thanks.