简体   繁体   English

子文件夹的角度路径给出错误

[英]Angular Route for sub folder gives error

I have written 2 ng-app in one project, one is user and the other admin . 我在一个项目中编写了2 ng-app ,一个是user ,另一个是admin To remove the # from the url I had used the below code in both app.config function 要从url中删除# ,我在app.config函数中使用了以下代码

$locationProvider.html5Mode(true);

and in app/index.html 并在app / index.html中

<base href="/">

and in app/admin/index.html 并在app / admin / index.html中

<base href="/admin/">

user app.js 用户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);
    }
]);

server.js server.js

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

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

I'm getting the following error, if there's an extra param in the route 如果路线中有额外的参数,我会收到以下错误

Uncaught SyntaxError: Unexpected token < 未捕获的SyntaxError:意外的令牌<

在此输入图像描述

The above error I get when my urls are 我的网址是我得到的上述错误

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

This works fine if the url is used without the last / ie 如果使用url而没有last / ie,这可以正常工作

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

I have refered to this questions too but couldn't resolve the issue 我也提到了这个问题,但无法解决问题

Node / Angular app Uncaught SyntaxError: Unexpected token < Node / Angular app Uncaught SyntaxError:意外的令牌<

How to use multiple index pages in angular 如何在角度中使用多个索引页面

Solution found 找到解决方案

The placement of the <base href="/"> was just before the </head> before which there were all scripts and links tags. <base href="/">位置就在</head>之前,之前有所有脚本和链接标记。 After adding the <base href="/"> after title tag the issue was resolved 在标题标记之后添加<base href="/">后,问题得以解决

The problem is with the express middleware, take for example 问题在于快速中间件,例如

app.use(express.static('./build/'));
// Any invalid calls for templateUrls are under app/* and should return 404
app.use('/app/*', function(req, res, next) {
  four0four.send404(req, res);
});
// Any deep link calls should return index.html
app.use('/*', express.static('./build/index.html'));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM