-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
如何让404页面不使用layout #2473
Comments
你是怎么设置的?把 /layouts/index.js 下的代码贴出来看看。 或者试试下面的代码。如果不行的话,可以打印 props.location.pathname 的值看一看是否等于 '/404'
|
我把props.location.pathname打印了,并不等于'/404'。而是我输入的不存在的路由。
|
@LingzhiLiu 你如果用约定式路由的话,我暂时没有好的建议。如果是配置式路由,这个问题还是比较容易解决的。 .umirc.js 文件或者 configs/config.js 文件添加 route 配置。
虽然功能实现了,但代码很不优雅,可以看到普通页面的路由必须前面加个前缀 其实我不太理解为什么你的 404 页面不嵌套在 BasicLayout 布局下。如果是做后管系统,也就是一个登陆页面,以及登录进来之后的普通页面,总共只需要两个布局而已。 登录页面,如果瞎输地址,可以通过代码一直保留在登录页面,做法是判断用户是否登录,比如是否存在 userId,未登录直接路由到登录页面; 登录成功后进入普通页面,如果瞎输地址,只是输入地址的页面不存在而已,404页面嵌套在 BasicLayout 中并无不可吧。 |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
我试了下@dkvirus 的方法,可以实现,但是存在几个问题:
于是我花了1天时间,发现有个更好的方法,这里做个记录:
这样就解决了:
|
还是上面的方法,继续完善一个需求,
目前的解决方法是可以将
然后修改运行时的
这样就能屏蔽这个url给出一个404页面了 |
在定义了layout的情况下,我在/pages下做了个自定义的404.js页面,production模式中任意输入一个不存在的路由展示的404页面还是用layout展示的。
我在layouts的Index.js里设定的当props.location.pathname === '/404'不走layout实际上是不起效的。
请问如何让404页面不使用layout呢?
The text was updated successfully, but these errors were encountered: