Panda Router
Match and destructure URLs based on RFC 6570 for URL templates:
import Router from "panda-router" router = Routercreate routeradd template: "/blog/posts/{key}" data: pagesview routeradd template: "/blog/posts/{key}{?token}" data: pagesedit match = routermatch "/blog/posts/my-first-post?token=miukhuJIguMjq5rXZzslww" assertequal truematch?assertequal matchdatapageseditassertdeepEqual matchbindings key: "my-first-post" token: "miukhuJIguMjq5rXZzslww"
Install
npm i -S panda-router
Limitations
-
Does not parse all of RFC 6570. For example, the length specifier
:
is not implemented. -
URL templates were not designed for destructuring, but rather expansion. Consequently, it's possible to define templates whose destructuring is not well-defined.