我尝试了很多东西,例如:
export async function getServerSideProps({ req, res }: any) {
if (req.headers.host === 'looshes.com') {
res.setHeader('Location', 'https://looshes.co.il' + req.url);
res.statusCode = 301;
res.end();
return { props: {} };
}
return {
props: {},
};
}
或:
useEffect(() => {
if (window.location.hostname === 'looshes.com') {
router.push('https://looshes.co.il' + router.asPath, undefined, { shallow: true });
}
}, [router]);
但对我没有任何用处。