【问题标题】:secondary level routing in node js changes root directorynode js中的二级路由更改根目录
【发布时间】:2017-03-22 00:58:18
【问题描述】:

在我的 web 项目中,我同时使用 angular JS 和 node JS。

为了在 Angular JS 中路由我的网址,我使用了以下代码

app.config(function($routeProvider,$locationProvider) {
$routeProvider
.when("/expert/:expertname*", {
    templateUrl : "public/views/individual_expert.html",
    controller:"usercontroller"
})
.otherwise({
        redirectTo:"/home"
    })
    $locationProvider.html5Mode(true);
});

以上情况生成的url如下,页面正常显示。

http://localhost:3002/expert/58200b0f3574801df4ef767c

当我从浏览器使用相同的 url 刷新我的页面时,执行同样的事情,我的 NODE JS 代码被执行。代码 sn-p 如下

app.get('/expert/:expertname',function(req,res){
    if(req.session.usersession!=null){
        if(req.session.usersession.type=="Member")
            res.sendfile('index/member_index.html');
        else if(req.session.usersession.type=="Expert")
            res.sendfile('index/expert_index.html');
        else if(req.session.usersession.type =="Admin")
            res.sendfile('index/admin_index.html');
        else
            res.sendfile('index/visitor_index.html');
    }
    else
        res.sendfile('index/visitor_index.html');
});

此时我在浏览器上看到的错误如下

1.) 我所有的 CSS 路径都已更改。

2.) 我所有的 JS 路径都改变了。

我注意到它正在用“专家”更改我的根目录并尝试搜索该目录中的所有导入。

我被困了很久。预先感谢您帮助我。

如果您没有正确理解我的问题,您可以发表评论。

【问题讨论】:

  • 请在链接到css和js的地方添加html代码。以及您期望的 URL。
  • 如果您的链接以点 . 开头,例如 ./css/style.css,则删除点。

标签: angularjs node.js angular-ui-router mean-stack


【解决方案1】:

在查看html页面中,有/css/style.css而不是普通的css/style.css

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-03
    • 2020-03-26
    相关资源
    最近更新 更多