问题
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) => dispatch => {
return axios.get(`api/topics/${id}`).then(res => {
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
回答1:
Add a leading slash to the url. Otherwise, it's a relative path and that happens.
api/topics/${id}
-> /api/topics/${id}
来源:https://stackoverflow.com/questions/52525634/axios-get-is-combining-the-url-when-sending-requests-to-the-backend