意外令牌<与React Router和Nginx一起使用

Cliche7

路由器配置:

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;
    }
}

使用babel(webpack)转译的所有文件。当我访问时,它工作正常,http://server:5002/somethingUnexpected token <如果访问http://server:5002/something/1抛出http://server:5002/something/

当我在Developer Tools中查看Sources选项卡时,我注意到该js文件已返回index.html作为其内容,这是由Request URL指向http://server:5002/something/app.js而不是引起的http://server:5002/app.js我是否需要在配置中添加一些内容以解决此问题?

草原狐狸

我认为src脚本标记中的JS文件路径存在问题

代替<script src="app.js"></script>,使用:<script src="/app.js"></script>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章