-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
想要在全局中间件中获取ctx._matchedRoute 有什么办法吗? #3009
Comments
Translation of this issue: Is there any way to get ctx._matchedRoute in the global middleware?Requirements: I want to get ctx._matchedRoute in a custom global middlewarePart of the code
At present, I have studied it and found that the test middleware can be mounted on a certain route to get ctx._matchedRoute. This should be caused by the order of loading routes and middleware of egg. But still do not give up want to ask ** Do you want to get ctx._matchedRoute in the global middleware? ** |
还是来说说你的原始需求吧,是不是想做权限管理啥的? |
好吧,原始需求
其中ctx._matchedRoute 输出结果为undefined,想请问如何解决在全局中间件中获取path-pattern |
放到 router middleware 试试 app.get('/', app.middleware.aclMiddleware(), 'controller'); |
谢谢,放到 router middleware 是可以的 |
执行顺序问题, |
需求:想在自定义的全局中间件里获取到 ctx._matchedRoute
部分代码
目前研究了一下,发现将test中间件单独挂载在某个路由上是能拿到 ctx._matchedRoute 的,这应该是egg的加载路由、中间件的顺序导致的。
但是还是不死心的想问问想要在全局中间件中获取ctx._matchedRoute 有什么办法吗?
The text was updated successfully, but these errors were encountered: