Reputation: 187
I want to use localePath in baseUrl but nuxt context is not available here. Is there any solution to make it possible. Thanks in Advance
axios.create({
baseURL: `${API_DOMAIN}/${localePath}/${apiURL}`,
headers: requestHeaders(),
paramsSerializer: (params) => Qs.stringify(params, { arrayFormat: 'brackets' }),
});
export default client;
Upvotes: 0
Views: 878
Reputation: 187
I fixed that one by checking if(!isServer)
let localePath = 'en'
const isServer = typeof window === "undefined"
if (!isServer) localePath = window.$nuxt.$store.$i18n.locale
axios.create({
baseURL: `${API_DOMAIN}/${localePath}/${apiURL}`,
headers: requestHeaders(),
paramsSerializer: (params) => Qs.stringify(params, { arrayFormat: 'brackets' }),
});
export default client;
Upvotes: 0