0

when react app is deployed to GAE , specific path request return 404. I have two path in my app. "/" and "/login" the first one works fine, but the other one does not.

this is my app.yaml configuration.

runtime: nodejs12
handlers:
  - url: /.*
    static_files: build/index.html
    upload: build/index.html
  - url: /
    static_dir: build

I tried some patterns such as

・ -url:(/.*) 
・ -url: /login
 static_files: build/index.html
 upload: build/index.html

But, none of them worked.

My routing is like this.

 <BrowserRouter>
      <Route exact path='/' component={Home} />
      <Route path='/login' component={LoginForm} />
    </BrowserRouter>

By specifying url , I thought I can get "/login" page, but it does not. Does someone know why this happen ?

Thank you !

john
  • 1
  • Check the CRA [deployment docs](https://create-react-app.dev/docs/deployment/) if there is a section relevant to the server environment (*each is different and require different setups/configurations/etc*) you are deploying your app to. If not there then check for any official documentation for how to redirect all page requests to your root index.html file so that your React app loads and can handle routing/navigation internally. This isn't an issue with React or `react-router-dom`. – Drew Reese Oct 02 '22 at 07:57
  • Can you switch the `handlers` order? It should try static files first. – 程柏硯 Oct 14 '22 at 09:36
  • I have an Angular [example](https://github.com/markxp/ncku-math-web), maybe you can convert it to React. See the [original question](https://stackoverflow.com/questions/50820400/serve-static-spa-from-google-cloud-storage-and-api-from-google-app-engine/73551753#73551753) – 程柏硯 Oct 14 '22 at 09:39

0 Answers0