update TS module route
This commit is contained in:
parent
75396b99c6
commit
a0b7f41bf5
1 changed files with 25 additions and 7 deletions
|
|
@ -1,21 +1,22 @@
|
|||
export default {
|
||||
const route = {
|
||||
methods: {
|
||||
route(
|
||||
routeName: string,
|
||||
parameters: Record<string, number | string> = {}
|
||||
): string | null {
|
||||
let route =
|
||||
Object.keys(window.__SYSTEM._routes).indexOf(routeName) !== -1
|
||||
? window.__SYSTEM._routes[routeName]
|
||||
const routes = route.flattenProperties(window.__SYSTEM._routes);
|
||||
const routeUrl =
|
||||
Object.keys(routes).indexOf(routeName) !== -1
|
||||
? routes[routeName]
|
||||
: null;
|
||||
if (!route) {
|
||||
return route;
|
||||
if (!routeUrl) {
|
||||
return routeUrl;
|
||||
}
|
||||
// copy parameters
|
||||
const iParameters = Object.assign({}, parameters),
|
||||
origin = window.location.origin,
|
||||
hash = window.location.hash;
|
||||
let pathname = route.replace(origin, ""),
|
||||
let pathname = routeUrl.replace(origin, ""),
|
||||
search = window.location.search;
|
||||
|
||||
// Replace in path name.
|
||||
|
|
@ -55,4 +56,21 @@ export default {
|
|||
return `${origin}${pathname}${search}${hash}`;
|
||||
},
|
||||
},
|
||||
flattenProperties(
|
||||
obj: Record<PropertyKey, any>,
|
||||
parent: string | null = null,
|
||||
res: Record<PropertyKey, any> = {}
|
||||
): Record<PropertyKey, any> {
|
||||
for (const key of Object.keys(obj)) {
|
||||
const propName = parent ? parent + "." + key : key;
|
||||
if (typeof obj[key] === "object") {
|
||||
route.flattenProperties(obj[key], propName, res);
|
||||
} else {
|
||||
res[propName] = obj[key];
|
||||
}
|
||||
}
|
||||
return res;
|
||||
},
|
||||
};
|
||||
|
||||
export default route;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue