Active route helpers
This package provide helpers for figuring out if some route or path is or isn't the currently active route.
Install
meteor add zimme:active-route
Supported routers
- [
ostrio:flow-router-extra
]
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
.
<li class="">...</li> <li class="">...</li> <li class="">...</li> <span>Show only if 'home' is the current route's name</span> <span>Show only if the current route's name begins with 'products'</span> <li class="">...</li> <li class="">...</li>
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
.
<li class="">...</li> <li class="">...</li> <li class="">...</li> <span>Show only if '/home' is the current route's path</span> <span>Show only if current route's path begins with '/products'</span> <li class="">...</li> <li class="">...</li>
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
.
<li class="">...</li> <li class="">...</li> <li class="">...</li> <span>Show only if 'home' isn't the current route's name</span> <span> Show only if the current route's name doesn't begin with 'products' </span> <li class="">...</li> <li class="">...</li>
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
.
<li class="">...</li> <li class="">...</li> <li class="">...</li> <span>Show only if '/home' isn't the current route's path</span> <span>Show only if current route's path doesn't begin with '/products'</span> <li class="">...</li> <li class="">...</li>
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
.
1ActiveRoute.name('home'); 2// Returns true if current route's name is 'home'. 3 4ActiveRoute.name(new RegExp('home|dashboard')); 5// Returns true if current route's name contains 'home' or 'dashboard'. 6 7ActiveRoute.name(/^products/); 8// 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
.
1ActiveRoute.path('/home'); 2// Returns true if current route's path is '/home'. 3 4ActiveRoute.path(new RegExp('users')); 5// Returns true if current route's path contains 'users'. 6 7ActiveRoute.path(/\/edit$/i); 8// Returns true if current route's path ends with '/edit', matching is 9// 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-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'}}
1// Configure helpers globally 2// The settings below are the package default settings 3ActiveRoute.configure({ 4 activeClass: 'active', 5 caseSensitive: true, 6 disabledClass: 'disabled', 7 regex: 'false' 8});
Notes
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