import { Router , QueryParams } from "./Router" ; /**
 * This is the root object of the application.
 * Do not use this class directly, make your own subclass instead.
 */ export class App { private static instance : App ; private router : Router ; private options : AppSettings ; /**
     * Constructor.
     */ constructor ( options ? ) { if ( App . instance ) { throw new Error ( "App instance exists; use getInstance() instead." ) ; } App . instance = this ; this . options = { ... DefaultAppSettings , ... options } ; if ( ! this . options . appBody ) { const el = document . createElement ( 'div' ) ; document . body . appendChild ( el ) ; this . options . appBody = el ; } this . router = new Router ( this ) ; } /** This method must be called after your App subclass is fully initialized. */ public load ( ) { this . router . loadController ( ) ; } public getRouter ( ) { return this . router ; } public getAppBody ( ) { return this . options . appBody ; } public static getInstance ( ) { return App . instance ; } path public navigate ( path , queryParams ? ) { if ( ! path || path [ 0 ] !== '/' ) { throw new Error ( "Invalid path" ) ; } this . router . navigate ( path , queryParams ) ; } /** Path to the root of the application. Does not end with '/' */ public getAppPath ( ) { return this . options . appPath ; } /** Gets the path to the currently displayed page. Returned string does not include application path. */ public getCurrentPagePath ( ) { const fullPath = window . location . pathname ; const len = this . options . appPath . length ; if ( fullPath . substr ( 0 , len ) === this . options . appPath ) { const pagePath = fullPath . substr ( len ) ; if ( ! pagePath ) { return '/' ; } if ( pagePath [ 0 ] === '/' ) { return pagePath ; } } return null ; } } export interface AppSettings { /** Path to the root of the application. Should NOT end with a '/'. Example: /myapp */ appPath ? : string ; /** The element which will serve as the root element of the application. */ appBody ? : HTMLElement ; } const DefaultAppSettings = { appPath : '' , appBody : null } ;