basis-stack/basis

View on GitHub
packages/client/src/components/router/rootRouter.jsx

Summary

Maintainability
A
0 mins
Test Coverage
import React from 'react';
import { Switch, Route } from 'react-router';

import routeTypes from '../../constants/routeTypes';

export default ({ routes }) => {

  const getRoute = (routeConfig, index) => {

    const props = {
      key: index,
      path: routeConfig.path,
      component: routeConfig.component,
      exact: routeConfig.type === routeTypes.page
    };

    return <Route {...props} />;
  };

  return (
    <>
      <Switch>
        { routes.filter(r => r.type === routeTypes.page ||
                            r.type === routeTypes.shellHub)
                .map(getRoute) }
        {/* TODO: Need to add a wildcard / not found route here...and use the ErrorView from basis-components */}
      </Switch>
    </>
  );
};