nmrony nmrony - 5 months ago 29
AngularJS Question

Weird behaviour of loopbackJS with AngularJS

I set html5mode(true) in my app.js. My code is as follows

$routeProvider.when( '/hello/there', {
templateUrl: 'partials/hello.html',
controller : 'HelloCtrl'
} );


// if none of the above routes are met, use this fallback
// which executes the 'AppCtrl' controller (controllers.js)
$routeProvider.otherwise( {
redirectTo: '/'
} );
$locationProvider.html5Mode(true);


But when I browse
http://localhost:3000/hello/there


It is thowing 404 error by Loopback raiseUrlNotFoundError. When I set html5Mode(false) all works fine

How to make it work then with html5Mode true?

Thanks in advance

Answer

You need to redirect all routes on the server side:

In server.js:

...
// -- Mount static files here--
// All static middleware should be registered at the end, as all requests
// passing the static middleware are hitting the file system
// Example:
app.use(loopback.static(path.resolve(__dirname, '../client'))); //mount static files first
...
app.all("/*", ...) //then redirect all routes
...
Comments