how to avoid HTTP status code 404 on nuxt error.vue

≡放荡痞女 提交于 2020-04-16 04:02:49

问题


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.

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.

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

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.


回答1:


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.



来源:https://stackoverflow.com/questions/61010374/how-to-avoid-http-status-code-404-on-nuxt-error-vue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!