Answer the question
In order to leave comments, you need to log in
How to properly use routing in Express + Angular?
Good afternoon!
How to correctly implement routing in Angular using template parts.
Now I had to reinvent the wheel, and do something like this routing:
Express :
app.get('/', (req, res) => {
if (req.xhr){
res.render('partial-index');
} else {
res.render('index');
}
});
.config(['$routeProvider', '$locationProvider',
($routeProvider, $locationProvider) => {
$locationProvider.html5Mode({
enabled: true,
requireBase: false
});
$routeProvider
.when("/", {
templateUrl: '/',
controller: 'MainCtrl'
})
.when("/about", {
templateUrl: '/about',
controller: 'AboutCtrl'
});
});
Answer the question
In order to leave comments, you need to log in
Most likely, if you use routing from angular, then your express should work as an api and it should not draw anything.
Something like this on the client
.state('login', {
cache: false,
url: '/login',
templateUrl: 'templates/auth/login.html'
});
---------
.controller('loginCtrl', function ($scope, Request, $state) {
$scope.login = function (operator) {
Request.sendRequest('Your/path/to/express/api/current/method', obj).then(
function resolve(resp) {
// handle success answer, call function to render some partial of html etc.
},
function reject(resp) {
// handle error
}
);
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question