Skip to main content

Application

Create the application instance

Create the application instance with the App class and pass the routes configuration.

Signature

export declare class App {
constructor(options: Options)
}

type Options = {
target: HTMLElement
routes: RouteConfig[]
mode: string
basePath: string
silentOnNotFound: boolean
};

type RouteConfig = {
path: string
component: Component
props: any
};

Parameters

ParameterTypeDefaultDescription
targetHTMLElement-Unique HTMLElement to build the application.
routesRouteConfig[]-Route definition list.
modestringhashRouter mode with hash or history.
basePathstring/The base URL of the app. For example, if the entire single page application is served under /app/, then basePath should use the value /app.
silentOnNotFoundBooleanfalseTells the router to ignore unknown route changes and not delete the currently displayed route. If a not found route is declared, it will also be ignored.

Example

src/app.js
import { App } from 'costro';
import Home from 'src/components/home';
import About from 'src/components/about';

const app = new App({
target: document.querySelector('#app'),
routes: [
{
path: '/',
component: Home
},
{
path: '/about',
component: About
}
]
});

Try it on CodeSandbox.

Import `App` with CDN links

Application is exposed in the global variable window.Costro.

const app = new Costro.Application();