Priya Kothwala Priya Kothwala - 1 month ago 5
AngularJS Question

secondary level routing in node js changes root directory

In my web project I am using angular JS and node JS both at the same time.

For routing my url in Angular JS I have used the below code

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


In the above case the url generated is as follows and the page is displayed properly.


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


This same thing is executed when I refresh my page with the same url from browser my NODE JS code is executed. The code snippet as below

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


At this time the errors I see on my browser are as follows

1.) All my CSS paths are changed.

2.) All my JS paths are changed.

The thing which I noticed was that it was changing my root directory with the "expert" and trying to search all the import in that directory.

I am stuck at this for long. Thank you in advance for helping me out.

You can comment if you don't get my question correctly.

Answer

in the view html page, have /css/style.css instead of normal css/style.css