0

In my service worker (which uses sw-toolbox library) I have setup two routes as follows:

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.

Am I using this sw-toolbox route config correctly?

Jimbo
  • 22,379
  • 42
  • 117
  • 159

1 Answers1

0

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"

Stef Chäser
  • 1,911
  • 18
  • 26
  • Thanks Stef. Tested and confirmed. Turns out my service worker wasnt updating during my previous tests of shuffling the order of these around. – Jimbo Apr 11 '18 at 08:06