2
0
mirror of https://github.com/esiur/iui.git synced 2025-12-17 03:50:24 +00:00
This commit is contained in:
2021-10-21 14:15:22 +03:00
parent fab9e186c9
commit 1e8ae99d39
15 changed files with 339 additions and 84 deletions

View File

@@ -116,7 +116,7 @@ export default IUI.module(class Router extends Target
return JSON.parse(JSON.stringify(rt));
}
async navigate(url, data, target, state)
async navigate(url, data, target, state, dataToQuery = true)
{
let q = url.match(/^\/*(.*?)\?(.*)$|^\/*(.*)$/);
@@ -132,8 +132,8 @@ export default IUI.module(class Router extends Target
}
// do we have data ?
else if (data !== undefined) {
path = q[3];
url = path + "?" + this._toQuery(data);
path = q[3];
url = dataToQuery ? path + "?" + this._toQuery(data) : path;
}
else {
path = q[3];
@@ -144,13 +144,19 @@ export default IUI.module(class Router extends Target
let [stateRoute, viewRoute] = this.getRoute(path, data);
if (stateRoute == null)
{
console.warn("State not found ", path);
return;
}
let ok = this._emit("navigate", { url, stateRoute, viewRoute, base: path, data, cancelable: true });
if (!ok)
{
console.warn("Route not allowed", path);
return;
}
// destination view not found
if (viewRoute == null) {
console.log(`Destination route not found ${stateRoute.dst}`);
@@ -173,11 +179,9 @@ export default IUI.module(class Router extends Target
// }
//}
if (!(target instanceof Target))
target = this;
if (state == null) {
let id = Math.random().toString(36).substr(2, 10);
state = { id, url, data, target, stateRoute, viewRoute };