2016-07-27 58 views
1

路由器配置:意外標記<與之反應路由器&Nginx的

const routes = 
[ 
    { 
     path: '/', 
     component: Layout, 
     onEnter: sessionFilter, 
     indexRoute: 
     { 
      component: ActivityIndex, 
      onEnter: sessionFilter 
     }, 
     childRoutes: 
     [ 
      { 
       path: 'login', 
       component: LoginPage 
      },{ 
       path: 'activity-new', 
       component: ActivityNew, 
       onEnter: sessionFilter 
      },{ 
       path: 'activity-edit/:id', 
       component: ActivityEdit, 
       onEnter: sessionFilter 
      } 
     ] 
    } 
]; 

ReactDOM.render(<Router routes={routes} history={browserHistory}/>, Node); 

Nginx的配置:

server { 
    listen 5002; 
    location/{ 
     root www/bc; 
     index index.html; 
     try_files $uri $uri/ /index.html; 
    } 
} 

與巴貝爾(的WebPack)transpiled所有文件。當我訪問http://server:5002/something時它工作正常,但如果我訪問http://server:5002/something/1http://server:5002/something/則拋出Unexpected token <

當我查看Developer Tools中的Sources選項卡時,我注意到js文件已經以index.html作爲其內容返回,這是由Request URL指向http://server:5002/something/app.js而不是http://server:5002/app.js引起的。我是否需要在配置中添加某些內容來解決此問題?

回答

1

我覺得在腳本標記中你的JS文件路徑的問題在src。使用:<script src="/app.js"></script>