Title: axios.get() is combining the url when sending requests to the backend.
Tags: react-redux;axios
Question: I'm sending a request to the backend via axios calls the URL on my address bar is
"localhost:3000/topics/5ba06e74dbc"
but in my browser inspector its returning an error
"localhost:3000/topics/api/topics/5ba06e74dbc 404 (Not Found)"
the request should be:
"localhost:3000/api/topics/5ba06e74dbc"
anyone know why that extra "topics/" is being added in front of the api call?
// my action call I suspect it might be because of my routes or because
//Im calling from topics/ already.
export const viewTopic = (id) =&gt; dispatch =&gt; {
return axios.get(`api/topics/${id}`).then(res =&gt; {
return dispatch({
type: VIEW_TOPIC,
payload: res.data
});
});
take a peek at my GitHub or ask for more info, I'm not sure what to include.
https://github.com/wolffles/bloccit-node/tree/frontend
Comment: lol thanks I didn't know that means its a relative path

Comment: Have you tried with /api/topics/${id} ? (start your url with / )

Here is the accepted answer: Add a leading slash to the url. Otherwise, it's a relative path and that happens.
api/topics/${id} -> /api/topics/${id}


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 2, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2018:00:09/26/18', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<react-redux><axios>', 'Title': 'axios.get() is combining the url when sending requests to the backend.', 'ViewCount': 3322, 'id': 52525634, 'user_AboutMe': '', 'user_AccountId': 9135433.0, 'user_DisplayName': 'Wolf_Tru', 'user_Reputation': 485.0, 'user_Views': 102.0, 'user_id': 6795280.0}}