P
P
prolina2019-07-09 13:25:22
React
prolina, 2019-07-09 13:25:22

Routing not working on hosting?

I am using create react app. Routing works locally. When uploaded to hosting - no. More precisely, if you simply enter mysite.by, and then switch to the menu, then everything works, that is, if you click "contacts" in the menu, it will go to mysite.by/contacts , and if you immediately enter mysite.by/ into the address bar contacts, it gives an error
5d246b6cab365845731630.png

class App extends React.Component {

  render() {
    return (
      <BrowserRouter>
         <div  className="app-wrapper-content"> 
         <Header />
            <Route path="/products" render={() => <ProductsContainer />} />
            <Route exact path="/" render={() => <MainPage />} />
            <Route exact path="/about" render={() => <About />} />
            <Route exact path="/jay_advices" render={() => <Advices />} />
            <Route exact path="/contacts" render={() => <ContactForm />} /> 
         </div>
          <Footer />
      </BrowserRouter>
    );
  }
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Spirin, 2019-07-09
@prolina

It looks like you have a static server on your hosting, or only the root route is processed. You need to give index.html for all non-static paths, then everything will work.
Serving Apps with Client Side Routing

C
CityCat4, 2019-07-09
@CityCat4

Routing is packet routing. If it did not work, it would be impossible to get to the hosting. And you just have a crooked site, maybe the baseurl is not taken into account, or vice versa, it is re-taken into account ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question