Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • C create-react-app
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 1,547
    • Issues 1,547
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 417
    • Merge requests 417
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Meta
  • create-react-app
  • Merge requests
  • !11356

Serve the root index.html for all client-side routes when hosted in Netlify or GitLab Pages

  • Review changes

  • Download
  • Email patches
  • Plain diff
Open Administrator requested to merge github/fork/nfriend/nfriend-add-_redirects-file into main Sep 01, 2021
  • Overview 1
  • Commits 1
  • Pipelines 0
  • Changes 2

Created by: nfriend

What does this PR do?

Adds a _redirects file that allows client-side pushState routing to work out of the box when deployed on Netlify or GitLab Pages.

More details about the _redirects file can be found here. Here's a section about this specific setup.

Relevant create-react-app docs

https://create-react-app.dev/docs/deployment#serving-apps-with-client-side-routing

How to test

  1. Create a new GitHub repo

  2. Scaffold a new project using this PR's branch of create-react-app

  3. Commit and push

  4. Using a Netlify account, connect Netlify to the new GitHub repo created in step #1

  5. Use the default Netlify options to deploy the site

  6. Verify that all URL routes result in the root index.html being served. For example, navigating to https://your-netlify-app-here.netlify.app/a/client/side/route should look like this: working

    In contrast, without the _redirects file, Netlify would serve up a 404 page:

    not-working

The process for testing on GitLab Pages is similar, although it involves a few extra steps (setting up a .gitlab-ci.yml pipeline to publish a Pages site).

Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/nfriend/nfriend-add-_redirects-file