function Redirect({ computedMatch, to, push = false, horizontal }) {
  return (
    <RouterContext.Consumer>
      {context => {
        invariant(context, "You should not use <Redirect> outside a <Router>");

        const { history, staticContext, horizontalRouter } = context;
        const method = push ? history.push : history.replace;
        const location = createLocation(
          computedMatch
            ? typeof to === "string"
              ? generatePath(to, computedMatch.params)
              : {
                  ...to,
                  pathname: generatePath(to.pathname, computedMatch.params)
                }
            : to
        );

        const perform = location => {
          if (horizontalRouter && horizontal) {
            let action = "open";
            if (location === false) {
              location =
                horizontalRouter.prevPath + horizontalRouter.prevSearch;
              action = "close";
            }
            method(location, {
              horizontalRoute: true,
              action,
              horizontalRouteId: horizontalRouter.horizontalRouteId
            });
          } else {
            method(location);
          }
        };

        // When rendering in a static context,
        // set the new location immediately.
        if (staticContext) {
          perform(location);
          return null;
        }

        return (
          <Lifecycle
            onMount={() => {
              perform(location);
            }}
            onUpdate={(self, prevProps) => {
              const prevLocation = createLocation(prevProps.to);
              if (
                !locationsAreEqual(prevLocation, {
                  ...location,
                  key: prevLocation.key
                })
              ) {
                perform(location);
              }
            }}
            to={to}
          />
        );
      }}
    </RouterContext.Consumer>
  );
}
/**
 * The public API for navigating programmatically with a component.
 */
The public API for navigating programmatically with a component.
The public API for navigating programmatically with a component .
function Redirect({ computedMatch, to, push = false, horizontal }) {
  return (
    <RouterContext.Consumer>
      {context => {
        invariant(context, "You should not use <Redirect> outside a <Router>");
        const { history, staticContext, horizontalRouter } = context;
        const method = push ? history.push : history.replace;
        const location = createLocation(
          computedMatch
            ? typeof to === "string"
              ? generatePath(to, computedMatch.params)
              : {
                  ...to,
                  pathname: generatePath(to.pathname, computedMatch.params)
                }
            : to
        );
        const perform = location => {
          if (horizontalRouter && horizontal) {
            let action = "open";
            if (location === false) {
              location =
                horizontalRouter.prevPath + horizontalRouter.prevSearch;
              action = "close";
            }
            method(location, {
              horizontalRoute: true,
              action,
              horizontalRouteId: horizontalRouter.horizontalRouteId
            });
          } else {
            method(location);
          }
        };
        if (staticContext) {
          perform(location);
          return null;
        }
        return (
          <Lifecycle
            onMount={() => {
              perform(location);
            }}
            onUpdate={(self, prevProps) => {
              const prevLocation = createLocation(prevProps.to);
              if (
                !locationsAreEqual(prevLocation, {
                  ...location,
                  key: prevLocation.key
                })
              ) {
                perform(location);
              }
            }}
            to={to}
          />
        );
      }}
    </RouterContext.Consumer>
  );
}
function Redirect ( { computedMatch , to , push = false , horizontal } ) { return ( < RouterContext . Consumer > { context => { invariant ( context , "You should not use <Redirect> outside a <Router>" ) ; const { history , staticContext , horizontalRouter } = context ; const method = push ? history . push : history . replace ; const location = createLocation ( computedMatch ? typeof to === "string" ? generatePath ( to , computedMatch . params ) : { ... to , pathname : generatePath ( to . pathname , computedMatch . params ) } : to ) ; const perform = location => { if ( horizontalRouter && horizontal ) { let action = "open" ; if ( location === false ) { location = horizontalRouter . prevPath + horizontalRouter . prevSearch ; action = "close" ; } method ( location , { horizontalRoute : true , action , horizontalRouteId : horizontalRouter . horizontalRouteId } ) ; } else { method ( location ) ; } } ; if ( staticContext ) { perform ( location ) ; return null ; } return ( < Lifecycle onMount = { ( ) => { perform ( location ) ; } } onUpdate = { ( self , prevProps ) => { const prevLocation = createLocation ( prevProps . to ) ; if ( ! locationsAreEqual ( prevLocation , { ... location , key : prevLocation . key } ) ) { perform ( location ) ; } } } to = { to } / > ) ; } } < / RouterContext . Consumer > ) ; }
The public API for navigating programmatically with a component.
The public API for navigating programmatically with a component .
// When rendering in a static context, // set the new location immediately.