import { AppMountParameters } from 'opensearch-dashboards/public' ; import ReactDOM from 'react-dom' ; import React from 'react' ; import { createHashHistory } from 'history' ; import { TodoAppPage } from './todo' ; export interface AppOptions { appInstanceId : string ; appTitle : string ; historyType : History ; } export enum History { Browser , Hash } export const renderApp = ( { appBasePath , element , history : platformHistory } , { appInstanceId , appTitle , historyType } ) => { const history = historyType === History . Browser ? platformHistory : createHashHistory ( ) ; ReactDOM . render ( < TodoAppPage history = { history } appInstanceId = { appInstanceId } appTitle = { appTitle } appBasePath = { appBasePath } isInitialRoute = { ( ) => { const stripTrailingSlash = ( path ) => path . charAt ( path . length - 1 ) === '/' ? path . substr ( 0 , path . length - 1 ) : path ; const currentAppUrl = stripTrailingSlash ( history . createHref ( history . location ) ) ; if ( historyType === History . Browser ) { return currentAppUrl === '' && ! history . location . search && ! history . location . hash ; } else { return currentAppUrl === '#' && ! history . location . search ; } } } />, element); return ( ) => ReactDOM . unmountComponentAtNode ( element ) ; } ;