我正在开发nextjs app。我通过使用query params('website.com/data?lang= en')。那么,当用户更改应用程序区域设置时,如何刷新或触发getServerSideProps(getStaticProps)?或者如何正确检测区域设置的变化?
// Client side change language
const changeLanguage = (locale) => {
router.push(router.asPath, router.asPath, { locale });
};
const fetchData = async (locale) =>
await client()
.get('/api/products', { params: { lang: locale } })
.then((res) => ({
index: res.data
}))
.catch(() => ());
export const getServerSideProps = async (context) => {
const { locale } = context;
const data = await fetchData(locale);
return {
props: data,
notFound
};
};
export default Index;
注意:路由器.推送不触发serversideprops
1条答案
按热度按时间xam8gpfp1#
如果你想做的只是重新加载页面,你可以浏览器
window.location.reload()
函数。