[英]secondary level routing in node js changes root directory
在我的web項目中,我同時使用了角度JS和節點JS。
為了在Angular JS中路由我的url,我使用了下面的代碼
app.config(function($routeProvider,$locationProvider) {
$routeProvider
.when("/expert/:expertname*", {
templateUrl : "public/views/individual_expert.html",
controller:"usercontroller"
})
.otherwise({
redirectTo:"/home"
})
$locationProvider.html5Mode(true);
});
在上述情況下,生成的URL如下,頁面正確顯示。
當我使用瀏覽器中的相同URL刷新我的頁面時執行同樣的操作我的NODE JS代碼被執行。 代碼片段如下
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路徑都已更改。
我注意到的是它正在用“expert”更改我的根目錄並嘗試搜索該目錄中的所有導入。
我被困在這里很久了。 提前謝謝你幫助我。
如果你沒有正確地回答我的問題,你可以發表評論。
在視圖html頁面中,有/css/style.css
而不是普通的css/style.css
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.