NUXT是否有可能确定哪个页面正在使用 /slug路径?
我的项目中有一个发布页面和一个类别页面以及通常的内部页面。
现在,我在页面文件夹中有以下结构:
- 页面/category/_id.vue-我发送类别
- 页的请求/post/post/_id.vue-发送请求发布
- 页面/page/page/_id.vue-发送请求 - 发送请求页。
该项目的API是用Laravel编写的(不知道它是否重要)。
我希望nuxt知道要发送的请求,获取类别或发布,然后选择所需的模板以显示类别或发布。如果没有类别或帖子,请重定向到第404页。是否可能?
I have a post page and a category page in my project as well as the usual internal pages.
Right now I have the following structure in the pages folder:
- pages/category/_id.vue - I send a request for a category
- pages/post/_id.vue - send request for post
- pages/page/_id.vue - send request for page.
The api for the project is written in laravel (don't know if it matters).
I want nuxt to know which request to send, to fetch category or post, and then choose desired template to display category or post. If there is no category or post, then make redirect to the page 404. Is it possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在这种情况下,API提供商无关紧要。仅VUE/NUXT页面模板生命周期中的逻辑。
每个页面模板因此,提供 id < / strong>的类别 /发布 /页面可以使用不同的端点从API获取数据。
哪个nuxt? 2或3?
在NUXT 2中,您应该使用特定页面模板的Asyncdata ex: post :
如果要强制404:
The API provider doesn't matter in this case. Only the logic within Vue/Nuxt page template lifecycle.
Every page template so category / post / page with provided id can use different endpoint to fetch the data from API.
Which Nuxt? 2 or 3?
In Nuxt 2 You should use asyncData of specific page template ex: post:
If You want to force 404: