Files
storage-service-ui/src/app.js

58 lines
2.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import './app.css';
import 'bootstrap/dist/css/bootstrap.min.css';
import 'bootstrap';
import './services/AdminConfigsService';
import ApiPage from './components/api-page';
import MainPage from './components/main-page';
import MainMenu from './components/main-menu/MainMenu';
import routeService from './services/RouteService';
import RouterPagesContainer from './components/router-pages-container/index';
import LogsPage from './components/logs-page/index';
import LoginPage from './components/login-page';
import authServiceApi from './api/AuthServiceAPI';
const initAppComponents = () => {
const mainMenu = new MainMenu();
mainMenu.render();
const routerPagesContainer = new RouterPagesContainer(mainMenu);
/**
* Добавление страниц в Роутинг выполняется на странице app.js
* @example
* routerPagesContainer.addRoutes([
* {url: '/', pageComponent: MainPage},
* {url: '/api', pageComponent: ApiPage},
* ]);
*/
routerPagesContainer.addRoutes([
{url: '/', pageComponent: MainPage},
{url: '/api', pageComponent: ApiPage},
{url: '/logs', pageComponent: LogsPage},
{url: '/login', pageComponent: LoginPage},
]);
/**
* Этот метод генерит событие Route, чтобы все компоненты получили его после инициализации.
* Поэтому вызывать его надо в самом конце, когда уже созданы все компоненты приложения.
* @example
* // Вызывать его можно только один раз в программе
* routeService.init();
*/
routeService.init();
};
const initApp = () => {
authServiceApi.refresh()
.then(() => {
initAppComponents();
})
.catch(() => {
history.pushState({}, '', '/login');
initAppComponents();
});
};
initApp();