React js路由无法在服务器上运行

时间:2017-09-26 12:08:31

标签: reactjs react-router

任何人都可以告诉我的代码有什么问题吗?

所有路由都在localhost(HashRouter)上运行,但在服务器上最后一条路由不起作用。当我访问https时:www.example.com/invoice_data/a/b - >只有“spinner”是可见的,看起来const isFetched是false,但它不是,因为其他路由正常工作。

render(){
const {language, langRequest} = this.props;
  const isFetched = langRequest.isFetched;
  let intlData = {};
  if (isFetched) {
     intlData = {
        locale: language,
        messages: langRequest.localeData[language].data
     };
     return process.env.NODE_ENV === 'production' ? (
         <IntlProvider key="intl" {...intlData}>
             <BrowserRouter>
                 <Switch>
                     <Route exact path='/' render={(props) => <p>Home</p>}/>
                     <Route exact path='/terms' render={(props) => <ExtraPage content="terms_list"/>}/>
                     <Route exact path='/terms/licence' render={(props) => <ExtraPage content="licence"/>}/>
                     <Route exact path='/terms/personal' render={(props) => <ExtraPage content="personal"/>}/>
                     <Route exact path='/password/:hash' render={(props) => <ExtraPage content="password" {...props}/>}/>
                     <Route exact path='/invoice_data/:hash/:idata' render={(props) => <ExtraPage content="invoice" {...props}/>}/>
                     <Route component={NotFound}/>
                 </Switch>
             </BrowserRouter>
         </IntlProvider>
     ) : (
         <IntlProvider key="intl" {...intlData}>
             <HashRouter>
                 <Switch>
                     <Route exact path='/' render={(props) => <p>Home</p>}/>
                     <Route exact path='/terms' render={(props) => <ExtraPage content="terms_list" footer="sticky"/>}/>
                     <Route exact path='/terms/licence' render={(props) => <ExtraPage content="licence"/>}/>
                     <Route exact path='/terms/personal' render={(props) => <ExtraPage content="personal"/>}/>
                     <Route exact path='/password/:hash' render={(props) => <ExtraPage content="password" {...props}/>}/>
                     <Route exact path='/invoice_data/:hash/:idata' render={(props) => <ExtraPage content="invoice" {...props}/>}/>
                     <Route component={NotFound}/>
                 </Switch>
             </HashRouter>
         </IntlProvider>
     )
  }else{
     return(
         <div className="loader-container centerizeH">
             <div className="loader">
                 <div className="spinner">
                     <div className="dot1"></div>
                     <div className="dot2"></div>
                 </div>
             </div>
         </div>
     )
  }
 }

.htaccess config:

  RewriteEngine On  
  RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
  RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
  RewriteRule ^ - [L]
  RewriteRule ^ /index.html [L]

0 个答案:

没有答案