nmrony nmrony - 1 year ago 122
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: '/'
} );

But when I browse

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 Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download