diff --git a/src/index.js b/src/index.js index e3610d5d..ec4f31fe 100644 --- a/src/index.js +++ b/src/index.js @@ -13,19 +13,63 @@ function loadLocaleData(language) { } } +const Apps = Object.freeze({ + LOGIN: { + id: 'login', + path: '/c/login' + }, + REGISTRATION: { + id: 'registration', + path: '/c/user/registration' + } +}); + +function router() { + let result = null; + + // Is it running ebedded ?. + const location = window.location; + if (location.pathname.indexOf('/c/') !== -1) { + const pathname = location.pathname; + result = Object.values(Apps).find(value => value.path.endsWith(pathname)); + } else { + // It's loaded from the npm start + const pageId = new URLSearchParams(location.search).get('app'); + result = Object.values(Apps).find(value => value.id == pageId); + } + if (result === null) { + result = Apps.LOGIN; + } + + console.log("router():" + result); + return result; +} + async function bootstrapApplication() { + + // Boostrap i18n ... const locale = (navigator.languages && navigator.languages[0]) || navigator.language || navigator.userLanguage || 'en-US'; const language = locale.split('-')[0]; - const messages = (await loadLocaleData(language)); - console.log(messages) - console.log(language) + // Todo: This is a temporal hack to rudimentary dispatch application. + let rootPage; + switch (router()) { + case Apps.LOGIN: + rootPage = ; + break + case Apps.REGISTRATION: + rootPage =
Register
; + break + default: + rootPage = ; + } + ReactDOM.render( - , + rootPage, document.getElementById('root') ) }