javascript - 子文件夹的 Angular Route 出错

标签 javascript angularjs node.js ngroute angularjs-ng-route

我在一个项目中写了2个ng-app,一个是user,另一个是admin。 要从 url 中删除 #,我在两个 app.config 函数中都使用了以下代码

$locationProvider.html5Mode(true);

在 app/index.html 中

<base href="/">

在 app/admin/index.html 中

<base href="/admin/">

用户 app.js

app.config(['$routeProvider','$locationProvider',
    function($routeProvider, $locationProvider) {
        $routeProvider.
        when('/properties', {
            templateUrl: 'views/modules/properties.html'
        })
        .when('/pages', {
            templateUrl: 'views/pages/pages.html'
        })
        .when('pages/editpages', {
            templateUrl: 'views/pages/editPages.html',
            controller: 'editPagesController',
        });

        $locationProvider.html5Mode(true);
    }
]);

服务器.js

app.use('/', express.static('app', { redirect: false }));

app.get('/*', function(req, res){
    res.sendFile(__dirname + '/app/index.html');
});

如果路由中有额外的参数,我会收到以下错误

Uncaught SyntaxError: Unexpected token <

enter image description here

当我的 url 是上面的错误

http://localhost:8080/properties/
http://localhost:8080/properties/something
http://localhost:8080/pages/
http://localhost:8080/pages/editpages   

如果在没有最后一个 / 的情况下使用 url,这会很好地工作,即

http://localhost:8080/properties
http://localhost:8080/pages

我也提到过这个问题,但无法解决问题

Node / Angular app Uncaught SyntaxError: Unexpected token <

How to use multiple index pages in angular

最佳答案

找到解决方案

<base href="/"> 的位置就在</head>之前之前有所有脚本和链接标签。添加 <base href="/"> 后标题标签后问题得到解决

关于javascript - 子文件夹的 Angular Route 出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40863547/

相关文章:

node.js - 在 mongoose.js 上保存钩子(Hook)之前使用的正确方法

javascript - 我如何告诉小部件最大化以填充整个可用空间?

javascript - Angular JS 和 Ionic - 从 ng-repeat 动态更改 img src

javascript - 使用过滤器延迟 ng-repeat 结果

node.js - 有没有办法预编译 node.js 脚本?

node.js - 为 node.js Web 服务应用程序安装服务器

javascript - 使表单根据从下拉框中选择的内容创建其他输入字段

javascript - jQuery - Google 图像功能在点击时滚动到无序列表行的顶部

javascript - 选择单选按钮时重新加载页面

angularjs - 如何在 onsenui 中创建日期和时间选择器?