Added route to onShown callback so that UI can be changed based on what route was shown.
This commit is contained in:
parent
05aaf6cf39
commit
ecc2711d64
@ -7,7 +7,7 @@ import { IgniteCallback} from "../ignite-html/ignite-html.js";
|
|||||||
* @class IgniteTemplate
|
* @class IgniteTemplate
|
||||||
* @memberof IgniteTemplate
|
* @memberof IgniteTemplate
|
||||||
* @param {String,String[]} routes A single or multiple set of routes that will invoke the callback if met.
|
* @param {String,String[]} routes A single or multiple set of routes that will invoke the callback if met.
|
||||||
* @param {Function(data)} showCallback A callback function that is called when the route is shown. Default is null.
|
* @param {Function(route, data)} showCallback A callback function that is called when the route is shown. Default is null.
|
||||||
* @param {Function} hideCallback A callback function that is called when the route is hidden. Default is null.
|
* @param {Function} hideCallback A callback function that is called when the route is hidden. Default is null.
|
||||||
* @param {Boolean} strict If true all routes must match before running the callback. Default is false.
|
* @param {Boolean} strict If true all routes must match before running the callback. Default is false.
|
||||||
* @returns {IgniteTemplate} This ignite template.
|
* @returns {IgniteTemplate} This ignite template.
|
||||||
@ -21,6 +21,7 @@ IgniteTemplate.prototype.route = function(routes, showCallback = null, hideCallb
|
|||||||
//Create an update method that will be used to check and see if the route is met.
|
//Create an update method that will be used to check and see if the route is met.
|
||||||
var update = (event) => {
|
var update = (event) => {
|
||||||
var routeMatches = false;
|
var routeMatches = false;
|
||||||
|
var matchedRoute = null;
|
||||||
|
|
||||||
//Create an object to hold any data.
|
//Create an object to hold any data.
|
||||||
var data = {};
|
var data = {};
|
||||||
@ -29,11 +30,13 @@ IgniteTemplate.prototype.route = function(routes, showCallback = null, hideCallb
|
|||||||
if (!strict) {
|
if (!strict) {
|
||||||
for (var i = 0; i < routes.length && !routeMatches; i++) {
|
for (var i = 0; i < routes.length && !routeMatches; i++) {
|
||||||
routeMatches = Router.matches(routes[i], data);
|
routeMatches = Router.matches(routes[i], data);
|
||||||
|
matchedRoute = routes[i];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
routeMatches = true;
|
routeMatches = true;
|
||||||
for (var i = 0; i < routes.length && routeMatches; i++) {
|
for (var i = 0; i < routes.length && routeMatches; i++) {
|
||||||
routeMatches = Router.matches(routes[i], data);
|
routeMatches = Router.matches(routes[i], data);
|
||||||
|
matchedRoute = routes[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,7 +46,7 @@ IgniteTemplate.prototype.route = function(routes, showCallback = null, hideCallb
|
|||||||
this.element.style.removeProperty("display");
|
this.element.style.removeProperty("display");
|
||||||
|
|
||||||
if (showCallback) {
|
if (showCallback) {
|
||||||
showCallback((event && event.data ? event.data : data));
|
showCallback(matchedRoute, (event && event.data ? event.data : data));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//Hide the route element.
|
//Hide the route element.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user