Then prepend each route should follow this layout, like /routes/_layout._page.($slug).tsx.
I my example, I want to render view (which will be nested from <Outlet /> in root.tsx) only for 404 status code, for other errors I throw new error to handle in root.tsx ErrorBoundary.
发布评论
评论(5)
tldr;
创建
路由/$。JSX
文件。可选地,您可以在该路线中添加此加载程序,以获取HTTP 404状态代码。link to doc
3种类型的观点
您应该在3种类型的 上显示自定义UI错误:
之类的意外错误无法读取未定义的
( erryboundary 在root.tsx
中)return json({errors:[{code:“ novaid”,messages:“ user doc doc day})})< /code>( catchboundary in
root.tsx
)route> routes/utaes> routes/
)也可以为每个嵌套路由定义一个errorboundary/catchboundary,如果您认为这会给用户一个更好的UX(例如在Tabs或文件夹中)。
TLDR;
Create a
routes/$.jsx
file. Optionally you can add this loader in that route in order to get an HTTP 404 status code.Link to doc
A wider perspective
You should show custom ui on 3 types of errors:
Cannot read properties of undefined
(ErrorBoundary inroot.tsx
)return json({ errors: [{code: "unpaid", message: "user didnt pay"}] })
(CatchBoundary inroot.tsx
)routes/
)Also you can define a ErrorBoundary/CatchBoundary for each nested route if you think that will give the user a better ux (like in tabs or folders).
您可以在
root.tsx
/root.tsx
中编辑cacterboundary
,然后返回任何要渲染的内容。相关文档在这里:
You can edit the
CatchBoundary
inroot.tsx
/root.tsx
and return whatever you want to render.Relevant documentation here: https://remix.run/docs/en/v1/guides/not-found#root-catch-boundary
您应该使用
errorboundary
使用嵌套的无路径布局为此。这样,我们正确处理状态代码,就可以使用路线。学分:
/routes/_layout.tsx
:upd:dop:不要忘记为非匹配路由添加splat路由
/routes/_layout。$。tsx
:然后预处每个路由应遵循此布局,例如
/routes/_layout._page。($ slug).tsx
。我的示例,我只想将视图从
&lt; utlet/&gt;
中嵌套在root.tsx
中,仅适用于404状态代码,对于其他错误i投掷
在root.tsx
errorboundary中处理的新错误。You should use
ErrorBoundary
using nested pathless layout for this. This way we properly handle status code we throw in routes.credits:
https://sergiodxa.com/tutorials/create-multiple-top-level-layouts-in-remix
/routes/_layout.tsx
:Upd: Don't forget to add splat route for non-matching routes
/routes/_layout.$.tsx
:Then prepend each route should follow this layout, like
/routes/_layout._page.($slug).tsx
.I my example, I want to render view (which will be nested from
<Outlet />
inroot.tsx
) only for 404 status code, for other errors Ithrow
new error to handle inroot.tsx
ErrorBoundary.如果上一个答案无法解决您的问题,请尝试此代码。将此代码放在
root.tsx
文件中。更多详细信息: https://remix.run/docs/docs/docs/en/main/main/main/route /错误边界
If the previous answer didn't solve your problem, try this code. Put this code in the
root.tsx
file.More details: https://remix.run/docs/en/main/route/error-boundary
混音不再支持CATCHBOUNDARY。请参考以下文档以获取更多详细信息
https://remix.remix.run/docs/docs/en/en/main/ start/v2#catchboundary and-orboundary
CatchBoundary is no longer supported by remix. Please refer the below docs for more details
https://remix.run/docs/en/main/start/v2#catchboundary-and-errorboundary