html5mode(true) issue with NodeJS

368 views
Skip to first unread message

Adnan Kukic

unread,
Sep 5, 2013, 6:05:04 PM9/5/13
to ang...@googlegroups.com
Hi,

I am having this strange issue with when html5mode is turned on.

Background:  I am running NodeJS Express for the backend, but having AngularJS do the routing on the app.  (Express handles my API routes)

so I capture everything and just render the index.html and let angular do it's thing:

app.get('*', function(req, res) {
res.sendfile('./public/index.html');
});

My angularJS routes look something like:

angular.module("app-name", ['services', 'ngResource'])
.config(function($routeProvider, $locationProvider) {
$routeProvider.when('/', {
templateUrl: 'views/homeview.html',
controller: 'homeCtrl'
});

$routeProvider.when('/login', {
templateUrl: 'views/loginView.html',
controller: 'loginCtrl'
});

$routeProvider.when('/register', {
templateUrl: 'views/registerView.html',
controller: 'registerCtrl'
});
               $routeProvider.otherwise({
redirectTo: '/'
});


This works perfectly.  I can access the login and register pages just fine, if i type in a route that doesn't exist like "/kdsaj" it just redirects to "/".

The issue I am having is when trying to capture params or deep-linking. 

So if i have a route that's '/about/contact' or '/users/:userId'  angular crashes each time.  The only error I get is: Uncaught SyntaxError: Unexpected token <

Has anyone experienced this problem before or knows any remedies?

Thanks,
Ado

Adnan Kukic

unread,
Sep 5, 2013, 6:34:17 PM9/5/13
to ang...@googlegroups.com
Some more information:

So i did a console.log on the req.url in node, which would get me the information of the request Url. 

When accessing first level links like /about , or /users  I get nothing in the log (because a new request isn't being made?)

but when trying to access deeper like /about/us or /overview/info, the console spits out:

/user/views/aboutView.html

or 

/user/views/usersView.html

Hope this helps.

Damien Galan

unread,
May 27, 2014, 1:57:46 PM5/27/14
to ang...@googlegroups.com
Did you figured out ? i have the same problem

Adnan Kukic

unread,
May 27, 2014, 2:03:09 PM5/27/14
to ang...@googlegroups.com
Hi Damien,

I did find the solution.  I am very busy right now - but will update this post later this week on how to fix it - it's really easy just has a few steps.

Thanks,
Ado

Александр Туранский

unread,
Aug 2, 2014, 11:10:16 AM8/2/14
to ang...@googlegroups.com
Hi, so how did you manage to solve the problem?


вторник, 27 мая 2014 г., 20:03:09 UTC+2 пользователь Adnan Kukic написал:

Abhilash Jaiswal

unread,
Feb 20, 2018, 8:24:00 AM2/20/18
to Angular and AngularJS discussion
Hi how did you managed to solve this? I am having the same issue
Reply all
Reply to author
Forward
0 new messages