Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React production router 404 after deep refresh firebase [duplicate]

i have this routes in my index.js

 <Router history={customHistory}>
        <div className="row">
            <Switch>
                <Route exact path="/login" component={Login}/>
                <Route path="/home" component={Home}/>
                <Route path="/politicas" component={Policies}/>

                <Redirect exact from="/" to="/login"/>
                <Route exact path="*" status={404} component={NotFound}/>

            </Switch>

        </div>
    </Router>

In local enviroment always works but i have one firebase application, to deploy my firebase project i use:

npm run build

and

firebase deploy

But in firebase app after deep refresh returns 404, the only route that works is "/", What do I have to do to keep the routes always working with any path?

like image 929
Abel Olguin Chavez Avatar asked Feb 16 '18 12:02

Abel Olguin Chavez


1 Answers

I answer myself, it is necessary to add the following to the file firebase.json

"hosting": {
  // Add the "rewrites" section within "hosting"
  "rewrites": [ {
    "source": "**",
    "destination": "/index.html"
  } ]
}
like image 139
Abel Olguin Chavez Avatar answered Nov 11 '22 20:11

Abel Olguin Chavez