This package provide helpers for figuring out if some route or path is or isn't the currently active route.
Because of support for kadira:flow-router
I've decided to rename
zimme:iron-router-active
to zimme:active-route
with version 2.0.0
.
meteor add zimme:active-route
iron:router
kadira:flow-router
meteorhacks:flow-router
(Deprecated)
If multiple routers are installed, the package will match against iron:router
routes first, then kadira:flow-router
and lastly meteorhacks:flow-router
.
Basic usage examples.
Template helper to check if the supplied route name matches the currently active route's name.
Returns either a configurable String
, which defaults to 'active'
, or
false
.
Template helper to check if the supplied path matches the currently active route's path.
Returns either a configurable String
, which defaults to 'active'
, or
false
.
Template helper to check if the supplied route name doesn't match the currently active route's name.
Returns either a configurable String
, which defaults to 'disabled'
, or
false
.
Template helper to check if the supplied path doesn't match the currently active route's path.
Returns either a configurable String
, which defaults to 'disabled'
, or
false
.
The following can be used by the template helpers as arguments.
- Data context, Optional.
String
orObject
withname
,path
orregex
name
, Optional.String
. Only available forisActiveRoute
andisNotActiveRoute
path
, Optional.String
. Only available forisActivePath
andisNotActivePath
regex
, Optional.String
orRegExp
At least one of Data context, route
or path
need to be supplied.
Basic usage examples.
Helper to check if the supplied route name matches the currently active route's name.
Returns either true
or false
.
ActiveRoute.name('home');
// Returns true if current route's name is 'home'.
ActiveRoute.name(new RegExp('home|dashboard'));
// Returns true if current route's name contains 'home' or 'dashboard'.
ActiveRoute.name(/^products/);
// Returns true if current route's name starts with 'products'.
Helper to check if the supplied path matches the currently active route's path.
Returns either true
or false
.
ActiveRoute.path('/home');
// Returns true if current route's path is '/home'.
ActiveRoute.path(new RegExp('users'));
// Returns true if current route's path contains 'users'.
ActiveRoute.path(/\/edit$/i);
// Returns true if current route's path ends with '/edit', matching is
// case-insensitive
The javascript helpers accepts String
or RegExp
as an argument.
activeClass
, Optional. Set toString
to change the defaultclass
forisActiveRoute
andisActivePath
caseSensitive
, Optional. Set tofalse
to make matching case-insensitivedisabledClass
, Optional. Set toString
to change the defaultclass
forisNotActiveRoute
andisNotActivePath
regex
, Optional. Set totrue
to make template helpers use regex matching with the following syntax,{{isActiveRoute '^home'}}
// Configure helpers globally
// The settings below are the package default settings
ActiveRoute.configure({
activeClass: 'active',
caseSensitive: true,
disabledClass: 'disabled',
regex: 'false'
});
- SHOULD be backwards-compatible with
zimme:[email protected]
ActiveRoute.config
is an alias forActiveRoute.configure
className
is an alias forclass
in template helpers- This package supports javascript's
RegExp
, here's some good info