简体   繁体   English

sw-toolbox路由器规则顺序/优先级如何工作?

[英]How does sw-toolbox router rule order/priority work?

In my service worker (which uses sw-toolbox library) I have setup two routes as follows: 在我的服务工作者(使用sw-toolbox库)中,我设置了两条路由,如下所示:

toolbox.router.any("/user/*", toolbox.networkOnly);
toolbox.router.any("/user/logout", toolbox.logoutHandler);

I assumed that the second rule which is specific to the "/user/logout" path, would act as an exception to the first rule (which is a blanket rule for the path "/user/*") however, I can confirm that it does not. 我假设特定于“ / user / logout”路径的第二条规则将成为第一条规则(这是路径“ / user / *”的总括规则)的例外,但是,我可以确认它不是。

Am I using this sw-toolbox route config correctly? 我是否正确使用此sw-toolbox路由配置?

I think the rules are independent, first matching rule wins. 我认为规则是独立的,首先匹配的规则将获胜。 So this should works: 所以这应该工作:

toolbox.router.any("/user/logout", toolbox.logoutHandler);
toolbox.router.any("/user/*", toolbox.networkOnly);

See Jeff's comment on this issues : "The routing to handlers should match in the order they're registered" 请参阅Jeff对这个问题的评论:“到处理程序的路由应按照它们注册的顺序匹配”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM