Centralize route generation to a single place

This commit is contained in:
dannyrb committed 2020-05-17 21:42:38 -04:00
1 parent eecdb62dda
commit a99badd011
15 files changed
+57 -34

No files matched your search

+95
View File
@@ -0,0 +1,95 @@
// External
import React from 'react';
import PropTypes from 'prop-types';
import { BrowserRouter, HashRouter } from 'react-router-dom';
import { ThemeWrapper } from '@ohif/ui';
// Viewer Project
// TODO: Should this influence study list?
import { appConfigContext } from './state/appConfig.context';
import { useAppConfig } from './hooks/useAppConfig';
import createRoutes from './routes';
import appInit from './appInit.js';
// Temporarily for testing
import '@ohif/mode-example';
/**
* ENV Variable to determine routing behavior
*/
const Router = JSON.parse(process.env.USE_HASH_ROUTER)
? HashRouter
: BrowserRouter;
let appConfig, commandsManager, extensionManager, servicesManager;
function App({ config, defaultExtensions }) {
const init = appInit(config, defaultExtensions);
// Set above for named export
appConfig = init.appConfig;
commandsManager = init.commandsManager;
extensionManager = init.extensionManager;
servicesManager = init.servicesManager;
// TODO: Expose configuration w/ context?
// See: `setConfiguration` in master
const appConfigImp = useAppConfig();
console.log('appConfigImp: ', appConfigImp);
return (
<appConfigContext.Provider value={appConfigImp}>
<Router basename={appConfig.routerBasename}>
<ThemeWrapper>
{createRoutes(
appConfig.modes,
appConfig.dataSources,
extensionManager,
appConfig,
appConfigImp
)}
</ThemeWrapper>
</Router>
</appConfigContext.Provider>
);
}
App.propTypes = {
config: PropTypes.oneOfType([
PropTypes.func,
PropTypes.shape({
routerBasename: PropTypes.string.isRequired,
oidc: PropTypes.array,
whiteLabeling: PropTypes.shape({
createLogoComponentFn: PropTypes.func,
}),
extensions: PropTypes.array,
}),
]).isRequired,
/* Extensions that are "bundled" or "baked-in" to the application.
* These would be provided at build time as part of they entry point. */
defaultExtensions: PropTypes.array,
};
App.defaultProps = {
config: {
/**
* Relative route from domain root that OHIF instance is installed at.
* For example:
*
* Hosted at: https://ohif.org/where-i-host-the/viewer/
* Value: `/where-i-host-the/viewer/`
* */
routerBaseName: '/',
/**
*
*/
showStudyList: true,
oidc: [],
extensions: [],
},
defaultExtensions: [],
};
export default App;
export { appConfig, commandsManager, extensionManager, servicesManager };