{"_id":"@dreamonkey/vue-routes-flattener","_rev":"2-c3d30eda0c9954b95a6afdaf5534daff","name":"@dreamonkey/vue-routes-flattener","dist-tags":{"latest":"1.0.0"},"versions":{"0.1.0":{"name":"@dreamonkey/vue-routes-flattener","version":"0.1.0","description":"A package that let you use grouping routes, logical routes without 'component' property meant to reduce repetition in their children paths","main":"dist/flat-routes.js","license":"MIT","keywords":["path","no component","flat"],"author":{"name":"Alessandro Vandelli","email":"a.vandelli@dreamonkey.com"},"typings":"dist/types/flat-routes.d.js","scripts":{"build":"rm -rf dist && tsc --declaration --declarationDir dist/types","test":"echo \"No test specified\" && exit 0","deploy":"yarn build && yarn publish --tag latest"},"devDependencies":{"typescript":"^4.0.3","vue":"^2.6.12","vue-router":"^3.4.7"},"publishConfig":{"access":"public"},"licenseText":"MIT License\n\nCopyright (c) 2020 Dreamonkey S.r.l.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","_id":"@dreamonkey/vue-routes-flattener@0.1.0","dist":{"shasum":"cae01481f5c5e34669f700adebb6c34f0e88b0ed","integrity":"sha512-kYs2P17btcXTAV6hPgJeuj11H2Hy4kHKroamED87H4RRYjTiA/d7PGixqIFL6631KiaDhUkiNEMhmWcWot/1BA==","tarball":"https://registry.npmjs.org/@dreamonkey/vue-routes-flattener/-/vue-routes-flattener-0.1.0.tgz","fileCount":10,"unpackedSize":11678,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfkbM1CRA9TVsSAnZWagAA6/QP/jRCAl2OYKM3LFS6Flq5\nhy1Ft4UwjzNtzt0Cr/uULYG5OW7/NLPaHA2siwLJ+0ztSID4+miys6jznKA4\ncUUDLq4G1RBuOp+2yo4+UPuD6PZMMCSlydOLSxUbzrI+OF8NLxtNWnlNtduH\n+8vLhhNkqlmp9SGjOkOj+FR900BrHM9f8WOCI9onC4JP5qxsTW9UjXXGjc+T\n+mox50Rs2xx0L3V94GIdaYY5PGbmVCq3Q3jAkbcBLY+obnChtKarUNkhVBzy\nMDaIMrlUxTiyEIKLL0CLBb8Wu49COghyNvFVkOsYiEH2Dh6CgWLiVgPF+PM7\n78K9NPCl12KJs1m/ETwe/PSrszL/zcTjK/v3md5r1FLrVST6EYeCbrYExCTW\nDb6vf9MH9haoWSpKiy2J7RPGYnDAhR4pYyzsawtGwi1oxOSwOPnp55h8rIWc\nzUv/v7kAJSmrWtEtBrRG55z7uFaDfsJTBoayzRHGQN+z6VwXL1GGS+YcVd8V\nB9u7SAYpRkYlz1Xb7JoLYJxwszjgeHJjhdqfrS8UDkiQVoFOFUm5i+OfIEqo\nY7UofX44DflX0ZvdWxCC4hp8cU8ESWDqB3ThkSpNLntCPAa2qhJtXZyAz+QI\nQemNCFejK/IMTaQSIVLjVARqqj7ea6l9DCL5n2MeH+qLzTiripvEtvVFEZX8\nTIZl\r\n=Gaix\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCRDcQLwnnJZ4DzplpWHeqSRenKriN8zQJeFc5Hd2/ZlgIgMahWtLHXI8O7I19GWfYsnIkbcvLpfVMiz1CAOSAMQl0="}]},"maintainers":[{"name":"mrkappa","email":"k.borghi@dreamonkey.com"},{"name":"ilcallo","email":"p.caleffi@dreamonkey.com"}],"_npmUser":{"name":"ilcallo","email":"p.caleffi@dreamonkey.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/vue-routes-flattener_0.1.0_1603384116915_0.5250413813368422"},"_hasShrinkwrap":false},"1.0.0":{"name":"@dreamonkey/vue-routes-flattener","version":"1.0.0","description":"A package that let you use grouping routes, logical routes without 'component' property meant to reduce repetition in their children paths","main":"dist/flat-routes.js","license":"MIT","keywords":["path","no component","flat"],"author":{"name":"Alessandro Vandelli","email":"a.vandelli@dreamonkey.com"},"typings":"dist/types/flat-routes.d.js","scripts":{"build":"rm -rf dist && tsc --declaration --declarationDir dist/types","test":"echo \"No test specified\" && exit 0","deploy":"yarn build && yarn publish --tag latest"},"devDependencies":{"@babel/types":"^7.17.0","typescript":"^4.6.3","vue":"^3.2.31","vue-router":"^4.0.14"},"peerDependencies":{"vue":"^3.2.0","vue-router":"^4.0.0"},"publishConfig":{"access":"public"},"licenseText":"MIT License\n\nCopyright (c) 2020 Dreamonkey S.r.l.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","_id":"@dreamonkey/vue-routes-flattener@1.0.0","dist":{"shasum":"e7059f629aa7ab636dc3dedb99d67f1062508418","integrity":"sha512-ECie4Ixx5jWegQXtSLnTdAHv9WMiInd6ScjNo0Qm9u4Ut0FiBMWq3T+BZtZ/LShI48V95RRakhK56aWqMZE7Pw==","tarball":"https://registry.npmjs.org/@dreamonkey/vue-routes-flattener/-/vue-routes-flattener-1.0.0.tgz","fileCount":12,"unpackedSize":13520,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQD/d3KNOn+c7KuWU2AD1fHB65KZ7zpt5DpZBwiei/KrzgIhALQgIYrCc/+zPzsxD/rd/OoMT87uaj2bnxpaP13+1rGR"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiTabfACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmodCg/+MaiHQxQrp1ueMLbt9kvKSpWNLF0tyKYJT1kltAVLaIaME7hm\r\nWgeTS+0Z6eIs7xpggGCg4end7BXFKtvgiyRoOLDE8A2W3s2cStmIDBjAiw2E\r\ne8/uu44VRoVYyo4BdL+hwEYoWrr9Mok/hfJAS+QlAv5HynETAcGnwA1isqv0\r\n8TgRjcBiDmzmRfn2hv3ii+VVlyVPu2DUuzuclodKW982h0Cqf3NxcEiS+SE7\r\nDb6XU9ZTL/DlqRf8EVm++EwMIVUwAoCkknmiLjqfbWLnpBG5C/3ySUq2FCdQ\r\n/Pu/2bYzNCZL+Atp8RFfKVHH2RG26WAiU8pGlnAVX4/jCAs/Ypi8cjx9xmt9\r\nthj1Unnafbv3nrMtWyO0JPceJPu14cBwU7IoqpCgFljmp+q+lOjghnf5uIih\r\nlMJDtDXsz9WW4fsRzXpa7q968iOi3jEIqzgPtct3ronzq6xKB0plWatzsk1Z\r\nCXFHu8GVLS4x5bKBOa48NccFJ+uOQ9nybnAlT2ViuvuFrrQ1e0w1UtRxN8sd\r\n+KmHNOtVLnRa0Vltrn5WTem2Ior1xW4er2NuURjn1nf+1u9etczJ4zMHXSm4\r\nxvF15cFLj7dIvVWsCp5gZVf8vKCW0T8Al53ZuYXdFuoVctI3LB8Jr5mOuunu\r\n89H6zVD7HZkkD2io2FWz9BpwVu/IMFMv0V4=\r\n=JAoQ\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"ilcallo","email":"p.caleffi@dreamonkey.com"},"directories":{},"maintainers":[{"name":"ilcallo","email":"p.caleffi@dreamonkey.com"},{"name":"mrkappa","email":"k.borghi@dreamonkey.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/vue-routes-flattener_1.0.0_1649256159463_0.7919907943893147"},"_hasShrinkwrap":false}},"time":{"created":"2020-10-22T16:28:36.692Z","0.1.0":"2020-10-22T16:28:37.018Z","modified":"2022-04-06T14:42:39.771Z","1.0.0":"2022-04-06T14:42:39.669Z"},"maintainers":[{"name":"ilcallo","email":"p.caleffi@dreamonkey.com"},{"name":"mrkappa","email":"k.borghi@dreamonkey.com"}],"description":"A package that let you use grouping routes, logical routes without 'component' property meant to reduce repetition in their children paths","keywords":["path","no component","flat"],"author":{"name":"Alessandro Vandelli","email":"a.vandelli@dreamonkey.com"},"license":"MIT","readme":"# vue-routes-flattener\n\nThis [package](https://www.npmjs.com/package/package) is meant to be used with [Vue Router](https://router.vuejs.org) and based on [this issue](https://github.com/vuejs/vue-router/issues/745).\nIt allows usage of grouping routes, logical routes without 'component' property meant to reduce repetition in their children paths.\nThis feature is purely additive and doesn't affect standard vue-router behaviour.\n\n## Install\n\n```bash\nyarn add @dreamonkey/vue-routes-flattener\n```\n\n## Use case\n\nSuppose you have a \"MainLayout\" component, containing a router outlet which displays these pages:\n\n- MainLayout\n  - Home -> '/home'\n  - NewYork -> '/locations/new-york'\n  - LosAngeles -> '/locations/los-angeles'\n  - Italy -> '/locations/italy'\n  - Contacts -> '/contacts\n\nAlso suppose you don't need a '/location' page containing a router outlet.\nYour routes configuration will be:\n\n```js\n// src/router/routes.ts\n\nimport { RouteConfig } from \"vue-router\";\n\nconst routes: RouteConfig[] = [\n  {\n    path: \"/\",\n    component: () => import(\"layouts/main-layout.vue\"),\n    children: [\n      { path: \"home\", component: () => import(\"pages/home.vue\") },\n      {\n        path: \"locations/new-york\", // <-- \"locations\" repetition\n        component: () => import(\"pages/new-york.vue\"),\n      },\n      {\n        path: \"locations/los-angeles\", // <-- \"locations\" repetition\n        component: () => import(\"pages/los-angeles.vue\"),\n      },\n      {\n        path: \"locations/italy\", // <-- \"locations\" repetition\n        component: () => import(\"pages/italy.vue\"),\n      },\n      {\n        path: \"contacts\",\n        component: () => import(\"pages/contacts.vue\"),\n      },\n    ],\n  },\n];\n\nexport default routes;\n```\n\n## Usage\n\nUsing this package you can reduce repetitions in code, while obtaining the same configuration at runtime:\n\n```js\n// src/router/routes.ts\n\nimport { RouteConfig } from \"vue-router\";\nimport { flatRoutes } from \"@dreamonkey/vue-routes-flattener\"; // <-- Import from the package\n\nconst routes: RouteConfig[] = flatRoutes([\n  // Apply the flattening === ^^^^^^^^^^\n  {\n    path: \"/\",\n    component: () => import(\"layouts/main-layout.vue\"),\n    children: [\n      { path: \"home\", component: () => import(\"pages/home.vue\") },\n      {\n        path: \"locations\", // <-- Grouping route, no 'component' is defined\n        children: [\n          {\n            path: \"new-york\", // <-- No repetition into child path\n            component: () => import(\"pages/new-york.vue\"),\n          },\n          {\n            path: \"los-angeles\", // <-- No repetition into child path\n            component: () => import(\"pages/los-angeles.vue\"),\n          },\n          {\n            path: \"italy\", // <-- No repetition into child path\n            component: () => import(\"pages/italy.vue\"),\n          },\n        ],\n      },\n      {\n        path: \"contacts\",\n        component: () => import(\"pages/contacts.vue\"),\n      },\n    ],\n  },\n]);\n\nexport default routes;\n```\n\nIf you forget to apply `flatRoutes`, Vue Router will throw an error because routes without 'component' property are not allowed.\n\n## Why this feature is not natively available\n\nThis feature is not natively available due to [some concerns exposed by Evan You](https://github.com/vuejs/vue-router/issues/745#issuecomment-263410514).\n\n> I think this breaks the relationship between route config nesting and router-view nesting and can make things a bit harder to reason about.\n\nURLs/paths are based on the filesystem, with its directories and files. Directories are the entry point of a new nesting level, while files are actual content.\n\nIf you think about our example configuration into as a filesystem structure (`D` = Directory, `f` = File) you'll probably get something like:\n\n```\n-MainLayout(D)\n|--Home(f)\n|--Locations(D)\n  |--NewYork(f)\n  |--LosAngeles(f)\n  |--Italy(f)\n|--Contacts(f)\n```\n\nVue Router configuration is based on router outlets instead. A router outlet open a new nesting level **and** is hosted into a component which could add content. In our comparison, the hosting component is **both** a directory and a file, and this can lead to confusing results in some edge cases.\n\nThe same example, using router outlets (`O`) as directories, would be:\n\n```\n-MainLayout(O)\n|--Home(f)\n|--Locations(O)\n  |--NewYork(f)\n  |--LosAngeles(f)\n  |--Italy(f)\n|--Contacts(f)\n```\n\nbut this would require you to create a dummy component containing only a router outlet.\nIf you also need a `Locations` page, for example an index with links to other Location-related pages, you would need to either have the dummy component dynamically change its template based on the current route or get rid of the router outlet altogether, flat out all routes and put there the new index component.\n\nThe former option increases the complexity of a component which should not be there in the first place, while the latter will generate repetition and lead to a de-sync between the URL structure (as you mentally imagine it when thinking about directories) and the configuration one.\n\n```\n-Main-layout(O)\n|--Home(f)\n|--Locations(f)\n|--Locations-NewYork(f)\n|--Locations-LosAngeles(f)\n|--Locations-Italy(f)\n|--Contacts(f)\n```\n\nThis package allows you to use \"virtual\" router outlets (aka grouping routes) which help you keep the configuration in sync with your directory-based mental model, then flattens the configuration at runtime.\nYou can also provide an \"index\" component (Locations page in our previous example) by specifying a child of the grouping route with an empty path (`\"\"`):\n\n```js\n// src/router/routes.ts\n\nimport { RouteConfig } from \"vue-router\";\nimport { flatRoutes } from \"@dreamonkey/vue-routes-flattener\";\n\nconst routes: RouteConfig[] = flatRoutes([\n  {\n    path: \"/\",\n    component: () => import(\"layouts/main-layout.vue\"),\n    children: [\n      { path: \"home\", component: () => import(\"pages/home.vue\") },\n      {\n        path: \"locations\", // <-- grouping route / \"virtual\" router outlet\n        children: [\n          { path: \"\", component: () => import(\"pages/locations.vue\") }, // <-- \"index\" component\n          {\n            path: \"new-york\",\n            component: () => import(\"pages/new-york.vue\"),\n          },\n          {\n            path: \"los-angeles\",\n            component: () => import(\"pages/los-angeles.vue\"),\n          },\n          {\n            path: \"italy\",\n            component: () => import(\"pages/italy.vue\"),\n          },\n        ],\n      },\n      {\n        path: \"contacts\",\n        component: () => import(\"pages/contacts.vue\"),\n      },\n    ],\n  },\n]);\n\nexport default routes;\n```\n\n## License\n\nMIT\n","readmeFilename":"README.md"}