| 1 |
/** |
| 2 |
* App Router |
| 3 |
* |
| 4 |
* TODO: Temporary solution for routing extensibility. |
| 5 |
*/ |
| 6 |
|
| 7 |
class Router { |
| 8 |
/** |
| 9 |
* @type {*[]} |
| 10 |
*/ |
| 11 |
routes = []; |
| 12 |
|
| 13 |
history = null; |
| 14 |
|
| 15 |
/** |
| 16 |
* |
| 17 |
* @param {{path: string, component: Object, props: Object}} route |
| 18 |
*/ |
| 19 |
addRoute( route ) { |
| 20 |
this.routes.push( route ); |
| 21 |
} |
| 22 |
|
| 23 |
getRoutes() { |
| 24 |
return this.routes.map( ( route ) => { |
| 25 |
const props = route.props || {}; |
| 26 |
// Use the path as a key, and add it as a prop. |
| 27 |
props.path = props.key = route.path; |
| 28 |
return React.createElement( route.component, props ); |
| 29 |
} ); |
| 30 |
} |
| 31 |
} |
| 32 |
|
| 33 |
const router = new Router(); |
| 34 |
|
| 35 |
// Make router available for use within packages. |
| 36 |
window.elementorAppPackages = { |
| 37 |
router, |
| 38 |
}; |
| 39 |
|
| 40 |
export default router; |
| 41 |
|