Added IgniteTemplate navigate function to allow dynamic routing based on properties or quickly set up routing.
This commit is contained in:
parent
ecc2711d64
commit
0cdf431aa0
@ -1,6 +1,6 @@
|
|||||||
import { IgniteElement } from "../ignite-html/ignite-element.js";
|
import { IgniteElement } from "../ignite-html/ignite-element.js";
|
||||||
import { IgniteTemplate, slot, div, html } from "../ignite-html/ignite-template.js";
|
import { IgniteTemplate, slot, div, html } from "../ignite-html/ignite-template.js";
|
||||||
import { IgniteCallback} from "../ignite-html/ignite-html.js";
|
import { IgniteCallback, IgniteProperty} from "../ignite-html/ignite-html.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a route listener that runs when a route is switched. The listener will run on construct the first time and update the state.
|
* Creates a route listener that runs when a route is switched. The listener will run on construct the first time and update the state.
|
||||||
@ -81,6 +81,23 @@ IgniteTemplate.prototype.route = function(routes, showCallback = null, hideCallb
|
|||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {String|IgniteProperty|Function} route The route to navigate to.
|
||||||
|
* @param {Any|IgniteProperty|Function} data The data to pass along with this navigate, this only applies when not refreshing, default is null.
|
||||||
|
* @param {Boolean|IgniteProperty|Function} refresh Whether or not to refresh the page, default is false.
|
||||||
|
* @returns {IgniteTemplate} This ignite template.
|
||||||
|
*/
|
||||||
|
IgniteTemplate.prototype.navigate = function(route, data = null, refresh = false) {
|
||||||
|
return this.onClick(() => {
|
||||||
|
Router.navigate(
|
||||||
|
(route instanceof IgniteProperty ? route.value : (route instanceof Function ? route() : route)),
|
||||||
|
(data instanceof IgniteProperty ? data.value : (data instanceof Function ? data() : data)),
|
||||||
|
(refresh instanceof IgniteProperty ? refresh.value : (refresh instanceof Function ? refresh() : refresh))
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
class RouterLink extends IgniteElement {
|
class RouterLink extends IgniteElement {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user