10 examples of 'npm react router dom' in JavaScript

Every line of 'npm react router dom' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
25function mountWithRouter (node) {
26
27 // Instantiate router context
28 const router = {
29 history: new BrowserRouter().history,
30 route: {
31 location: {},
32 match: {},
33 },
34 }
35
36 const createContext = () => ({
37 context: { router, t: () => {} },
38 childContextTypes: { router: shape({}), t: () => {} },
39 })
40
41 return mount(node, createContext())
42}
8export function Router({children, ...props}) {
9 assert(props.location, 'Router "location" property is missing')
10
11 const routes = useMemo(() => addRoutes(children), [])
12 return renderMatch(routes, props)
13}
10export default function withNamedRouter(ChildComponent) {
11 return function NamedRouter(props) {
12 const routerValue = useContext(RouterContext)
13 const namedRoutes = useContext(RouterConfigContext)
14 const history = useMemo(() => namedHistory(routerValue.history, namedRoutes), [routerValue])
15 return (
16
17 )
18 }
19}
11function withRouter(Component) {
12 const displayName = `withRouter(${Component.displayName || Component.name})`;
13 const C = props => {
14 const { wrappedComponentRef, ...remainingProps } = props;
15
16 return (
17
18 {context => {
19 invariant(
20 context,
21 `You should not use <${displayName} /> outside a `
22 );
23 return (
24
25 );
26 }}
27
28 );
29 };
30
31 C.displayName = displayName;
32 C.WrappedComponent = Component;
33
34 if (__DEV__) {
35 C.propTypes = {
36 wrappedComponentRef: PropTypes.oneOfType([
37 PropTypes.string,
38 PropTypes.func,
39 PropTypes.object
40 ])
41 };
42 }
43
44 return hoistStatics(C, Component);
45}
178ReduxibleRouter.prototype.getRouterWithDevTools = function getRouterWithDevTools() {
179 var DevTools = this.devTools;
180 return _react2.default.createElement(
181 'div',
182 null,
183 this.getRouter(),
184 ' ',
185 _react2.default.createElement(DevTools, null)
186 );
187};
17export function createRouteFromReactElement(element) {
18 var type = element.type;
19 var route = createRoute(type.defaultProps, element.props);
20
21 if (route.children) {
22 var childRoutes = createRoutesFromReactChildren(route.children, route);
23
24 if (childRoutes.length) route.childRoutes = childRoutes;
25
26 delete route.children;
27 }
28
29 return route;
30}
18export function renderWithReduxStore( reactElement, domContainer, reduxStore ) {
19 const domContainerNode =
20 'string' === typeof domContainer ? document.getElementById( domContainer ) : domContainer;
21
22 return ReactDom.render(
23
24 { reactElement }
25 ,
26 domContainerNode
27 );
28}
17render() {
18 const {children} = this.props;
19 // No children means nothing to render.
20 if (!children) return null;
21
22 // That makes nested routes working.
23 const propsForChildren = {...this.props};
24 delete propsForChildren.children;
25
26 // Delete route to prevent overwrite of correct value.
27 delete propsForChildren.route;
28
29 return React.cloneElement(children, propsForChildren);
30}
26RouterRender(props) {
27 switch (this.props.store.state) {
28 case 'loading': {
29 return ('Loading...');
30 }
31 case 'error': {
32 return ('Error');
33 }
34 case 'ready': {
35 return (
36 <main>
37 );
38 }
39 }
40 return null;
41}</main>
48public render() {
49 return this._resolveRoute();
50}

Related snippets