Active route helpers
This package provide helpers for figuring out if some route or path is or isn't the currently active route.
Package rename
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
.
Install
meteor add zimme:active-route
Supported routers
If multiple routers are installed, the package will match against iron:router
routes first, then kadira:flow-router
and lastly meteorhacks:flow-router
.
Template helpers
Usage
Basic usage examples.
isActiveRoute
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
.
isActivePath
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
.
isNotActiveRoute
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
.
isNotActivePath
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
.
Arguments
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.
Javascript helpers
Usage
Basic usage examples.
ActiveRoute.name
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'.
ActiveRoute.path
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
Arguments
The javascript helpers accepts String
or RegExp
as an argument.
Global options
-
activeClass
, Optional. Set toString
to change the defaultclass
forisActiveRoute
andisActivePath
-
caseSensitive
, Optional. Set tofalse
to make matching case-insensitive -
disabledClass
, 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'
});
Notes
- SHOULD be backwards-compatible with
zimme:iron-router-active@1.0.4
-
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