React Router - Uncaught SyntaxError: Unexpected to

2019-08-23 11:04发布

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条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-08-23 11:23

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: '/'

查看更多
登录 后发表回答