React Router - Uncaught SyntaxError: Unexpected token < when refreshing an URL with params

混江龙づ霸主 提交于 2020-01-06 05:26:06

问题


I am using react 16 and react router 4, webpack and webpack dev server.

I do have the following Route:

<Route path="/company/:symbol" render={this.getCompanyPageRoute} />

And I do navigate to this route through the following:

this.props.history.push('/company/blablabla');

Everything works fine. But if I refresh the page with this URL, I get the following error:

Uncaught SyntaxError: Unexpected token <

I've seen that there are several posts of this error, but I was not albe to fix the issue following those links.


回答1:


Posting the answer if it could help someone else.

Changing the output property of the webpack config to the following fixed the issue:

output: {
        path: BUILD_DIR,
        publicPath: '/',
        filename: 'bundle.js',
    }

The trick is made by: publicPath: '/'



来源:https://stackoverflow.com/questions/52313844/react-router-uncaught-syntaxerror-unexpected-token-when-refreshing-an-url-w

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!