Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-router-dom-wrapping

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-router-dom-wrapping

Custom route wrapping functionality for react-router-dom

  • 1.0.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-50%
Maintainers
1
Weekly downloads
 
Created
Source

npm bundle size GitHub release (latest by date) npm-donwloads-per-year


react-router-dom-wrapping

Custom route wrapping functionality for react-router-dom

Install

$ npm install --save react-router-dom-wrapping

or

$ yarn add react-router-dom-wrapping

API

wrapRoutes({ routes, fieldsToOmit, wrapRoute })

routes

Type: IncomingRoute[]. IncomingRoute extends { children?: IncomingRoute[] }

fieldsToOmit

Type: (keyof IncomingRoute)[]

wrapRoute

Type: (props: IRouteWrapperProps<IncomingRoute>) => React.ReactNode

  • route IncomingRoute
  • config IReactDomRoutesWrapperConfig

Usage


/**
 * - title setting
 * - lazy loading (Suspence)
 * - ErrorBoundary
 */
export const RouteWrapper: FC<TExtendedRouteObject> = ({ element, title }) => {
  useEffect(() => {
    document.title = title;
  }, [title]);

  const pendingMessage = useMemo(() => `Page is loading - ${title}`, [title]);

  return (
    <Suspense fallback={<div>{pendingMessage}</div>}>
      <ErrorBoundary>
        {element}
      </ErrorBoundary>
    </Suspense>
  );
};


const config: IReactDomRoutesWrapperConfig<IIncomingRoute> = {
  routes: [
    {
      fieldToOmit1: 'fieldToOmit1',
      fieldToOmit2: 'fieldToOmit2',
      title: 'first',
      children: [
        {
          fieldToOmit1: 'fieldToOmit1',
          fieldToOmit2: 'fieldToOmit2',
          title: 'first-first',
          children: [
            {
              title: 'first-first-first',
              fieldToOmit1: 'fieldToOmit1',
              fieldToOmit2: 'fieldToOmit2',
            }
          ],
        }
      ],
    },
    {
      fieldToOmit1: 'fieldToOmit1',
      fieldToOmit2: 'fieldToOmit2',
      title: 'second',
      children: [
        {
          fieldToOmit1: 'fieldToOmit1',
          fieldToOmit2: 'fieldToOmit2',
          title: 'second-first',
          children: [
            {
              title: 'second-first-first',
              fieldToOmit1: 'fieldToOmit1',
              fieldToOmit2: 'fieldToOmit2',
            }
          ],
        }
      ],
    },
  ],
  fieldsToOmit: [
    'fieldToOmit1',
    'fieldToOmit2',
  ],
  wrapRoute: (props) => <RouteWrapper element={<div>test<div/>} title={props.route.title} />,
};

const routes = wrapRoutes<IIncomingRoute, OutcomingRoute>(config);

TODO

  • [+] implementation
  • [+] units
  • [+] docs
  • [+] scripts for npm
  • [+] publish (github, npm)
  • badges (ci, coverage)
  • add to corporate registry
  • tell friends
  • custom omit

License

MIT © Kas Elvirov

Keywords

FAQs

Package last updated on 16 May 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc