jquery-atomic-nav
Concise jQuery routing and navigation plugin based on nested navigation states.
This library is designed to work with component-based application UIs. Heavily inspired by the state-machine approach of AngularJS UI Router and modern techniques like Promises that emphasize immutable, functional state.
Unlike AngularJS UI Router and most other routing libraries, Atomic Nav routes are defined on-demand. This allows for a better, more elegant composition of widgets with no need for the massive central "routes" file.
For more examples see /example/index.html
.
Example code:
var rootNav = $.navigationRoot();
rootNav.when('/foo', function (fooNav) {
console.log('entered "foo" state');
$(fooNav).on('destroyed', function() {
console.log('left "foo" state');
});
fooNav.when('/bar', function (barNav) {
console.log('entered "foo/bar" state');
$(barNav).on('destroyed', function() {
console.log('left "foo/bar" state');
});
});
});
rootNav.when('/baz/:someParam', function (someParam, bazNav) {
console.log('entered "baz" state with "' + someParam + '"');
$(bazNav).on('destroyed', function() {
console.log('left "baz" state with "' + someParam + '"');
});
});
Composition example:
function RootView() {
var rootNav = $.navigationRoot();
var $dom = $('body');
rootNav.when('/fizz-buzz', function (fizzBuzzNav) {
var fizzBuzzView = new FizzBuzzView($dom, fizzBuzzNav);
});
}
function FizzBuzzView($dom, nav) {
nav.when('/foo-bar', function (fooBarNav) {
});
}