prollynomial / Cartier

A small, unopinionated client-side router.
MIT License
0 stars 0 forks source link

There needs to be a way to add routes after instantiation #3

Closed prollynomial closed 10 years ago

prollynomial commented 10 years ago

Routes can only be assigned in the constructor, which causes problems if context objects are to navigate.

/* If Context wants to be able to navigate here it can't: */
var HomeContext = require('./HomeContext');

var routes = {
  '/': HomeContext
};

window.Nav = new Cartier(routes, notFound, contextChanged);

So to solve this we should require the Contexts after Cartier is instantiated, but:

var routes = {
  '/': 'UhOh'
};

window.Nav = new Cartier(routes, notFound, contextChanged);

/* HomeContext now can navigate, but route contexts are not contextual data */
var HomeContext = require('./HomeContext');

So ideally:

window.Nav = new Cartier(contextChanged);

var HomeContext = require('./HomeContext');

var routes = {
  '/': HomeContext
};

window.Nav.routes(routes);
window.Nav.onNotFound(notFound);

This way, HomeContext has access to the Cartier instance, and routes can contain contextual data.