Reputation: 43
I am having trouble with my axios post request:
I am using https://www.npmjs.com/package/next-i18next
and it prepends the language url to the api when sending a post request -- however I do not wish this behaviour
My axios request :
const { data } = await axios.post(`api/login`, {
email,
password,
});
results in :
localhost:3000/language/api/login
My Next config :
const { i18n } = require("./next-i18next.config");
const nextConfig = {
reactStrictMode: true,
swcMinify: true,
i18n,
};
module.exports = nextConfig;
next-i18next.config.js
module.exports = {
i18n: {
defaultLocale: "en",
locales: ["en", "ua"],
localePath: "./locales",
},
};
... I want all my url request routes to go to the correct routing when the language is selected ... but I do not want my api requests to. They can just go to the default english.
How to change this behaviour?
Thx!
Upvotes: 0
Views: 143
Reputation: 921
try changing
const { data } = await axios.post(`api/login`, {
email,
password,
});
to this
const { data } = await axios.post(`/api/login`, {
email,
password,
});
Upvotes: 1