Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import PropTypes from 'prop-types'
import { compose, setDisplayName, setPropTypes, defaultProps, withHandlers, mapProps } from 'recompose'
import { connect } from 'react-redux'
import { push, replace, goBack } from 'react-router-redux'
import { Route } from 'react-router-dom'
import { pick } from 'lodash'
export default compose(
setDisplayName('ModalRoute'),
setPropTypes({
closePath: PropTypes.string, // Path to redirect to on model close
...Route.propTypes
}),
defaultProps({
closePath: null, // closePath === null -> history goBack on close modal
}),
connect(null, {
routerPush: push,
routerReplace: replace,
routerGoBack: goBack
}),
withHandlers({
render: ({ routerPush, routerReplace, routerGoBack, closePath, component, render }) => (props) => {
// takes precedence over so don’t use both in the same
if (component) { return undefined }
const toggle = (e, replace) => closePath
? (replace === true ? routerReplace(closePath) : routerPush(closePath))
: routerGoBack()
if (Component) {
return ;
} else if (typeof render === 'function') {
return render(contentProps);
}
}} />
);
}} />
);
}
}
ScreenRoute.propTypes = {
...Route.propTypes,
path: PropTypes.string.isRequired,
title: PropTypes.string,
isContextRoot: PropTypes.bool
};
export default ScreenRoute;
import React from "react";
import PropTypes from "prop-types";
import { Route } from "react-router-dom";
class ConditionalRoute extends React.PureComponent {
static propTypes = {
...Route.propTypes,
component: PropTypes.func,
render: PropTypes.func,
redirectPath: PropTypes.string,
active: PropTypes.bool,
fallbackRender: PropTypes.func,
fallbackComponent: PropTypes.func,
};
static defaultProps = {
component: undefined,
render: undefined,
active: false,
redirectPath: "/",
fallbackRender: undefined,
fallbackComponent: undefined,
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import pathToRegexp from 'path-to-regexp'
import qs from 'qs';
import {
Route as ReactRouterRoute,
Link as ReactRouterLink,
} from 'react-router-dom';
export class Route extends Component {
static displayName = 'PatchedRoute';
static propTypes = {
location: ReactRouterRoute.propTypes.location,
}
static contextTypes = {
router: ReactRouterRoute.contextTypes.router,
}
render() {
let location = this.props.location || this.context.router.route.location;
if (location && location.search && location.search.length > 1) {
location = { ...location };
location.query = qs.parse(location.search.substring(1));
}
return
}
}
mapProps((props) => ({
...pick(props, Object.keys(Route.propTypes)),
})),
)(Route)