Skip to content

Latest commit

 

History

History
67 lines (46 loc) · 2.51 KB

configuration.md

File metadata and controls

67 lines (46 loc) · 2.51 KB

Router Configuration

Router class

Descends from Cherrytree class. Accepts an Cherrytree options hash and renderRoot as arguments

Cherrytree options:

Option Default Description
log noop Called with logging info - takes true, false or a custom logging function
logError true Called when transitions error (except TransitionRedirected and TransitionCancelled). Takes true, false, or a custom function
pushState false Use browser History API or the default hash change
root / Used in combination with pushState: true - if your app isn't served from /, pass the new root
interceptLinks (same as pushState) When pushState: true this intercepts all link clicks, preventing the default behavior. This can take a function to set custom behavior - see intercepting links
qs object The parser function for query strings with a simple parser. Pass in an object with parse and stringify functions to customize the handling of query strings.

renderRoot:

A Marionette Region or a HTML element or a CSS selector.

Optionally the render root can be defined setting a Marionette Region to rootRegion property

const router = new Router({log: true}, '#main');

router.map(fn)

Configures the route map. e.g.

router.map(function (route) {
  route('app', {path: '/', abstract: true}, function () {
    route('about', {viewClass: AboutView, viewOptions: {version: '1.0'}})
    route('post', {path: ':postId', routeClass: PostRoute}, function () {
      route('edit', {routeClass: PostRoute, viewClass: EditPostView})
    })
  })
})

Each route can be configure with the following options:

  • routeClass: a Route class
  • routeOptions: options passed to the Route constructor
  • viewClass: a Marionette.View class. Can be used alone or with routeClass
  • viewOptions: options passed to the Marionette.View constructor
  • path: the route path
  • abstract: pass true to define an abstract route
  • outlet: pass true to allow a viewClass without an outlet region

All routes must have at least viewClass or routeClass defined.

For more information about route mapping refer to cherrytree documentation

router.listen

Starts listening for URL changes

router.rootRegion

Property that defines the Marionette Region where the top level views will be rendered

router.destroy

Cleanup a router. This is mostly used for testing.