This package provide helpers for figuring out if some route or path is or isn't the currently active route.
This is based on zimme:active-route
with functionality removed and bugs added.
This was written as an exercise to learn how to Meteor's package system works, and to remove features and dependencies so that this package's core functionality can be more easily maintained by someone who is still learning JavaScript and meteor.
meteor add greenmoose:active-route-basic
Only the one, hence active-route-basic. If you use multiple routers, you want
zimme:active-route
and not this package.
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
.
ActiveRouteBasic.name('home');
// Returns true if current route's name is 'home'.
ActiveRouteBasic.name(new RegExp('home|dashboard'));
// Returns true if current route's name contains 'home' or 'dashboard'.
ActiveRouteBasic.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
.
ActiveRouteBasic.path('/home');
// Returns true if current route's path is '/home'.
ActiveRouteBasic.path(new RegExp('users'));
// Returns true if current route's path contains 'users'.
ActiveRouteBasic.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
ActiveRouteBasic.configure({
activeClass: 'active',
caseSensitive: true,
disabledClass: 'disabled',
regex: 'false'
});
- No promises about backwards compatibility.
className
is an alias forclass
in template helpers- This package supports javascript's
RegExp
; see here for some good info