react-router@4 打包后 通过/a/b 访问报错

nixchen
  • -3
新手上路,请多包涵

在开发环境中,通过/info/boss可以正常访问,但是打包后通过/info/boss访问不到,报错

main.5fc0fc94.js:1 Uncaught SyntaxError: Unexpected token 

如果通过dispatch(push('/a/b') 还是可以正常访问的,刚开始接触React,麻烦大家指点一下,谢谢!
配置的路由代码如下:

<Provider store={store}>
      <PersistGate persistor={persistor}>
        <ConnectedRouter history={browserHistory}>
          <Switch>
            <Route path={'/football'} component={Football}/>
            <Route path={'/button-sliding'} component={ButtonSliding}/>
            <Route path={'/rectangular-loader'} component={RectangularLoader}/>
            <Route path={'/diagonal-border'} component={DiagonalBorderEffects}/>
            <Route path={'/mg3D-button'} component={MG3DButton}/>
            <Route path={'/ss-toggle'} component={SSToggle}/>
            <Route path={'/blue-dazzling-diamond'} component={BDDiamond}/>
            {/*练习*/}
            <Route path={'/login'} component={Login}/>
            <Route path={'/register'} component={Index}/>
            <Route path={'/info/boss'} component={BossInfo}/>
            <Route path={'/info/genius'} component={GeniusInfo}/>
            <Route path={'/test'} component={Dashboard}/>
          </Switch>
        </ConnectedRouter>
      </PersistGate>
    </Provider>

Nginx配置:

server {
    listen 80;
    autoindex on;
    server_name t-cxp.test.com;
    access_log E:/myinstall/nginx-1.10.2/logs/access.log combined;
    location / {
        root F:/workspace/nginx-root;
        index index.html index.htm;
        try_files $uri /index.html;
    }
}
回复
阅读 1.5k
1 个回答

应该是打包生成的js路径是相对路径,多层路由的时候查找js路径出错了,打包生成的路径改成绝对路径试试

宣传栏