{"id":16824818,"url":"https://github.com/jaforbes/mithril-map-router","last_synced_at":"2025-04-11T03:20:59.062Z","repository":{"id":57298438,"uuid":"46647764","full_name":"JAForbes/mithril-map-router","owner":"JAForbes","description":"Map over route changes like you map over arrays!","archived":false,"fork":false,"pushed_at":"2017-07-27T17:02:01.000Z","size":5,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-10T08:45:12.776Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JAForbes.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-11-22T05:26:19.000Z","updated_at":"2017-09-22T16:17:52.000Z","dependencies_parsed_at":"2022-09-06T03:31:46.692Z","dependency_job_id":null,"html_url":"https://github.com/JAForbes/mithril-map-router","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JAForbes%2Fmithril-map-router","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JAForbes%2Fmithril-map-router/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JAForbes%2Fmithril-map-router/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JAForbes%2Fmithril-map-router/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JAForbes","download_url":"https://codeload.github.com/JAForbes/mithril-map-router/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248334040,"owners_count":21086304,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-13T11:12:06.892Z","updated_at":"2025-04-11T03:20:59.039Z","avatar_url":"https://github.com/JAForbes.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mithril-map-router\nMap over route changes like you map over arrays!\n\n\u003e WARNING: This library only works with mithril's 0.2.x API.  If you are using 1.0 take a look at the [authentication section of the docs](https://mithril.js.org/route.html#authentication)\n\n#### Getting start\n\n`npm install mithril-map-router`\n\nNow let's give every route access to a `data` object for shared context.\nEasy with ramda's `R.always`.\n\n```js\nvar R = require('ramda');\nvar m = require('mithril')\nvar mapRoutes = require('mithril-map-router')(m)\n\n/*\n  Automatically parameterize every component\n  with the data object.\n  \n*/\nmapRoutes(R.always(data), container, '/' ,{\n\t'/': Home,\n\t'/access/login': Login, \n\t'/access/verify': Verify, \n\t'/access/invite': Invite, \n\t'/access/forgot': Forgot, \n\t'/access/reset': Reset, \n\t'/access/signup': SignUp, \n})\n```\n\nOr you could do something more advanced like check if the user is logged in on route change.\n\n```js\nvar authRedirect = function(routeName){\n  var token = localStorage.getItem('auth_token')\n  if(!token){\n    m.route('/login')\n  }\n}\n\nmapRoutes(authRedirect, container, '/' ,{\n\t'/': Home,\n\t'/login': Login\n})\n```\n\n## Documentation\n\n##### Initialization\n\nYou must pass in your mithril `m` object to initialize the router module.\nYou'll then be given access to the `mapRoutes` function.\n\n##### mapRoutes\n\nArguments: `( visitor: function, container: HTMLElement, initialRoute: string, routes: object )`\n\nCalls the `visitor` function every time mithril triggers a route change.  \nYour `controller` will receive the result of the visitor function as its first argument.\n\nWorks with parameterized components just fine.\n\nThe other arguments work just like [`m.route`](https://lhorie.github.io/mithril/mithril.route.html)\nbecause this function just proxies to it.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaforbes%2Fmithril-map-router","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjaforbes%2Fmithril-map-router","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaforbes%2Fmithril-map-router/lists"}