Is react-router messing with the API Url?

I have a API which works fine, but when used with react, the get request … Read more Is react-router messing with the API Url?

I have a API which works fine, but when used with react, the get request goes to

/api/profile/posts/profile/matt

whereas it should go to:

/api/posts/profile/matt

The proxy is set on localhost:8000, which works fine for the other APIs when working with react.

Code for calling the APIs(Only profile one doesn’t work, rest all work fine, even the profile one works when I use the absolute URL):

const res = username 
            ? await axios.get("posts/profile/"+username)
            : await axios.get("posts/timeline/6120b0e07ea0361eb4982b1c");

code for routes:

function App() {
  return (
    <Router>
      <Switch>
        <Route exact path="/">
          <Home />
        </Route>
        <Route path="/login">
          <Login />
        </Route>
        <Route path="/register">
          <Register />
        </Route>
        <Route path="/profile/:username">
          <Profile />
        </Route>
      </Switch>
    </Router>
  )
}

similar problem as this user: How to prevent React-router from messing up your API url

Source: React – Stack Overflow



Leave a Reply

Your email address will not be published. Required fields are marked *