我目前正在使用Vue.js和Nuxt框架进行网站内部化。我正在从一个页面的网址website.com/my-page
移动到website.com/<lang>/my-page
。
为了做到这一点,并关注documentation,我已将所有页面移动到_lang
文件夹中,为我提供以下架构:
pages/
│
└───_lang
│ │
| |__ my-page.vue
|
...
除了<lang>
slug现在是强制性的这一事实之外,这完全符合预期,使得访问website.com/my-page
返回404。
我希望这个url以我的应用程序中声明的默认语言显示页面。
我发现实现这一目标的唯一方法是在my-page.vue
的根部创建另一个pages/
,其中包含以下内容:
<script>
import Mypage from '~/pages/_lang/my-page'
export default Mypage
</script>
但是,这意味着为我的网站的每个页面创建这种别名,给我:
pages/
│
│─── my-page.vue
│
└───_lang/
│ │
| |__ my-page.vue
|
...
有没有办法让这个自动化,因为这是一个非常繁琐的过程?
谢谢,
旁注:我一直在调查extendRoutes没有成功。
你可以使用router-extras-module模块。
<router>
alias:
- /my-page
</router>