如何避免在nuxt error.vue上使用HTTP状态代码404 [英] how to avoid HTTP status code 404 on nuxt error.vue

查看:170
本文介绍了如何避免在nuxt error.vue上使用HTTP状态代码404的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Nuxt,我们需要能够渲染伪路由,如下所示:

Using Nuxt, we need to be able to render pseudo-routes, like this:

https://server.com/non-existent-route

不存在的路线"是动态路径.

Where "non-existent-route" is a dynamic path.

通常,这将呈现error.vue.很好,因为我们已经破坏了对该页面的使用以呈现我们想要的内容.但是...我们刚刚发现Nuxt仍在发送404!仅出于某种原因,仅在首次将页面加载到新选项卡中时才会发生这种情况.这很糟糕.

Normally, this would render error.vue. This is fine, as we've subverting the use of this page to render what we want. But... we just discovered that Nuxt is sending a 404 anyway! This only happens when the page is first loaded in a fresh tab, for some reason. This is very bad.

因此,在某些情况下,我们需要一种避免HTTP状态404的方法.

So, we need a way to avoid HTTP status 404 in some cases.

我们发现了这一点: https://medium.com/finn-no/hacking-nuxts-404-logic-for-maximum-and-easy-proxying-e4efaeb03d66 实际上,它没有我们希望的那样有用,因为它只是提供了一种代理另一个URL的方式,使我们回到相同的问题.

We found this: https://medium.com/finn-no/hacking-nuxts-404-logic-for-maximum-awesome-and-easy-proxying-e4efaeb03d66 which is actually not as helpful as we had hoped it would be, as it simply provides a way to proxy another URL, sending us back to the same problem.

我们怀疑可能有一些中间件解决此问题的方法...但是还没有提出.

We suspect there might be some middleware solution to this problem... but have not been able to come up with it.

推荐答案

答案一直都在这里: https://nuxtjs.org/guide/routing#dynamic-nested-routes 令人失望的是,没有人提出这个极其简单的解决方案.

Turns out the answer was right here all long: https://nuxtjs.org/guide/routing#dynamic-nested-routes Rather disappointing that nobody suggested this extremely simple solution.

这篇关于如何避免在nuxt error.vue上使用HTTP状态代码404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆