nextjs重定向默认路由

时间:2020-09-23 07:43:58

标签: reactjs next.js

我的文件夹结构。

pages
  settings
    index.tsx
    apple.tsx
    banana.tsx
    coffee.tsx

我有4条路线可以访问。

/settings//settings/apple/settings/banana/settings/coffee

当我访问/settings时,我会将其重定向到/settings/apple

我尝试使用useRouter()

settings / index.tsx

...
const router = useRouter();
React.useEffect(()=>{
  router.replace('/settings/apple');
},[]);
...

但是,现在我正在使用i18n,但是我期望它不起作用。

我希望重定向到localhost:3000/en/settings/apple,但是它已重定向到localhost:3000/settings/apple

我的问题是如何在保持i18n的情况下正确重定向到默认路由?

0 个答案:

没有答案