可以使用子目录重写URL

发布于 2025-01-30 09:56:49 字数 256 浏览 1 评论 0原文

我的项目结构默认

- pages
 - login.vue
 - index.vue
 auth
 - about.vue

情况下,NUXT可以使用'localhost:3000/'访问路径,并且它将由/pages/index.vue渲染。
如果我想访问dir auth中的页面,则必须是访问路径 'local主持:3000/auth/关于
但是我想通过'localhost:3000/about
访问路径

I have project structure like this

- pages
 - login.vue
 - index.vue
 auth
 - about.vue

by default, nuxt can access a path with 'localhost:3000/' and it will rendered by /pages/index.vue

in case if i want to access a page in dir auth/about it's must be access a path
'localhost:3000/auth/about'

but i want to access path with 'localhost:3000/about

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

凑诗 2025-02-06 09:56:49

您可以使用页面别名点

<script setup>
definePageMeta({
  alias: ['/about']
})
</script>

<template>
  <div>this is an auth page</div>
</template>

使以下文件结构

”在此处输入图像描述“

可以通过/about/auth/aid about访问。

You can use a page alias if you want to have another entry point

<script setup>
definePageMeta({
  alias: ['/about']
})
</script>

<template>
  <div>this is an auth page</div>
</template>

So that the following file structure

enter image description here

could be accessed via either /about or /auth/about.

榆西 2025-02-06 09:56:49

在NUXT 3.13和NUXT 4中,您可以使用页面分组:

(auth)
- about.vue

In Nuxt 3.13 and Nuxt 4, you can use page grouping:

(auth)
- about.vue
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文