I have a API that works fine, but when i use it 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/api, that works fine for the other APIs when is 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>
)
}
I have similar problem with this user as well: How to prevent React-router from messing up your API url
exact, or change the routes names.