Home
Support Forums

How to set base tag during build for internal redirect

I asked a previous question about proper configuration for an “internal redirect” for a React application:

This thread resolved my issue and I was able to successfully perform an internal redirect as per the previous thread, but I had to use a hard-coded <base> tag in order to do so. We want to be able to connect Deploy Previews in this way, but I don’t see a way to do this with static <base> tags.

The DEPLOY_PRIME_URL env var

seems to have the value we need for the <base> tag, but I can’t figure out a way to use it in the build for a create-react-app project because CRA does not allow env vars other than ones named PUBLIC_URL or follow the REACT_APP_* convention.

I haven’t found a way to reconcile the CRA env var conventions with DEPLOY_PRIME_URL since the latter is not available at build time. Is there a way yet to create the functionality we need?

You might want to take a look at this for clues:

This works, and PUBLIC_URL=$DEPLOY_PRIME_URL react-scripts build ended up being a particularly good fit for our need.

Thanks @hrishikesh!