{"id":17772740,"url":"https://github.com/jamesplease/backbone.premium-router","last_synced_at":"2025-03-15T16:31:47.655Z","repository":{"id":22983439,"uuid":"26333729","full_name":"jamesplease/backbone.premium-router","owner":"jamesplease","description":"(WIP) A premium routing solution for Backbone.","archived":false,"fork":false,"pushed_at":"2015-02-26T06:52:30.000Z","size":357,"stargazers_count":7,"open_issues_count":10,"forks_count":2,"subscribers_count":5,"default_branch":"master","last_synced_at":"2023-04-09T20:56:48.298Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jamesplease.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-11-07T19:08:26.000Z","updated_at":"2015-09-24T17:38:59.000Z","dependencies_parsed_at":"2022-08-21T08:11:00.840Z","dependency_job_id":null,"html_url":"https://github.com/jamesplease/backbone.premium-router","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamesplease%2Fbackbone.premium-router","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamesplease%2Fbackbone.premium-router/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamesplease%2Fbackbone.premium-router/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamesplease%2Fbackbone.premium-router/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jamesplease","download_url":"https://codeload.github.com/jamesplease/backbone.premium-router/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221587287,"owners_count":16848072,"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-26T21:40:37.116Z","updated_at":"2024-10-26T21:40:37.608Z","avatar_url":"https://github.com/jamesplease.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# backbone.premium-router\n[![Travis build status](http://img.shields.io/travis/jmeas/backbone.premium-router.svg?style=flat)](https://travis-ci.org/jmeas/backbone.premium-router)\n[![Code Climate](https://codeclimate.com/github/jmeas/backbone.premium-router/badges/gpa.svg)](https://codeclimate.com/github/jmeas/backbone.premium-router)\n[![Dependency Status](https://david-dm.org/jmeas/backbone.premium-router.svg)](https://david-dm.org/jmeas/backbone.premium-router)\n[![devDependency Status](https://david-dm.org/jmeas/backbone.premium-router/dev-status.svg)](https://david-dm.org/jmeas/backbone.premium-router#info=devDependencies)\n\nA premium routing solution for Backbone.\n\n### Features\n\n- Callbacks for the most common actions when changing URLs: fetching data, then showing views\n- Easily add authentication/authorization to routes\n- Cancel navigation (for instance, if a Model is unsaved)\n- Re-route during transitions\n- Extends from Backbone.Router, rather than replacing it\n\n### Motivation\n\nBackbone's Router was developed to only be used when the page first loads. In other words, passing `trigger: true` to `navigate` is discouraged.\nThis is an approach to routing that is rapidly declining in popularity in web development. Even within the Backbone community, fewer and fewer Backbone\ndevelopers are using the Router in the intended way. Other popular frameworks, like Ember, Angular, and React, all take the approach of\nactivating route handlers **every** time a URL matches. By doing so, you can move much of the management of application state into the router,\nsimplifying your application's code tremendously.\n\nThis fundamental difference in how Backbone approaches routing manifests itself in the API the Backbone Router exposes: it is simple to a fault.\nPremiumRouter is a small extension to Backbone's Router that makes it **drastically** more powerful.\n\n### Getting Started\n\nThe PremiumRouter extends from a regular Backbone Router. Because of this, its API for registering routes may be familiar to you.\n\n```js\n// Create a new PremiumRouter\nvar router = new Backbone.PremiumRouter({\n  \n  // Just like Backbone's Router, we can pass our routes\n  // in at creation time. Instead of a callback, though, associate\n  // Route classes with your URLs.\n  routes: {\n    'home': HomeRoute,\n    'books/:bookId': BookRoute\n  }\n});\n```\n\nA Route is a Class that exists on the `PremiumRouter` class. In the simplest implementation,\nthey can be used to fetch data, and then show a view. These two actions will happen each time\nthe Route is matched.\n\n```js\n\n// The base Route Class is attached to the ObjectRoute\nvar BookRoute = Backbone.PremiumRouter.Route.extend({\n\n  // Fetch is called when the route is entered. Use it\n  // to fetch data.\n  fetch: function(routeData) {\n\n    // In this case, we're fetching a model called `book`.\n    return book.fetch();\n  },\n\n  // Once the data has been fetched, we create a new BookView,\n  // render it, then attach it to the `body` of the page.\n  show: function() {\n    new BookView()\n      .render()\n      .$el.appendTo('body');\n  }\n});\n```\n\nAs you might have guessed, both fetching and showing are optional. If your route doesn't need to do one, or both,\nof those things, simply omit them.\n\nThis is just a small taste of what's possible with the PremiumRouter. For more, refer to the API documentation below.\n\n### API\n\nComing soon!\n\n### Caveats\n\nAvoid using `Backbone.history.navigate` when using the `PremiumRouter`. Always go through the `navigate` method\non the router or route instances.\n\n### Problems not solved by PremiumRouter\n\nPremiumRouter does not make any changes to Backbone.history. Accordingly, you must keep these things in\nmind:\n\n1. Routes are **still** matched in a first-come-first-serve basis.\n2. `trigger: true` must always be passed to `navigate` if you wish for the Route to be\n  changed.\n\n### FAQ\n\n#### Should I use `trigger: true`?\n\nYes, always. Backbone's official recommendation is to never use `trigger: true`, but the standard Backbone\nRouter is not intended to be used in the same way that PremiumRouter is. Backbone's style of routing comes\nfrom the jQuery days of development, and it has essentially been abandoned by the greater web development community.\n\n#### Are there any other libraries related to Routing that work well with this library?\n\n[Backbone.Intercept](https://github.com/jmeas/backbone.intercept) is a library integrates well with the PremiumRouter. It makes it easier to\nautomatically manage `trigger: true` when users of your application click links.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjamesplease%2Fbackbone.premium-router","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjamesplease%2Fbackbone.premium-router","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjamesplease%2Fbackbone.premium-router/lists"}