Skip to content

Instantly share code, notes, and snippets.

@tuchk4
Last active December 1, 2015 09:44
Show Gist options
  • Save tuchk4/7ad1707ee0aed2df673a to your computer and use it in GitHub Desktop.
Save tuchk4/7ad1707ee0aed2df673a to your computer and use it in GitHub Desktop.
Configuration - Valentjs vs AngularJS
angular.module('example').provider('app.route', ['$routeProvider', function($routeProvider) {
return {
when: function(path, config) {
if (!config.resolve) {
config.resolve = {};
}
// Add resolver for each registered route
config.resolve.permission = function() {
// ...
};
return $routeProvider.when(path, config);
},
otherwise: (config) {
// ....
}
}
});
angular.module('example').config(['app.routeProvider', '$rootScope', '$locationProvider', '$provide',
function($appRouteProvider, $rootScope, $locationProvider, $provide) {
// Add exception handler
$provide.decorator('$exceptionHandler', function ($delegate) {
return function(exception, cause) {
console.log('exception');
}
});
// Enable HTML5 mode
$locationProvider.html5Mode({
enabled: true
});
// Setup otherwise redirect
$appRouteProvider.otherwise({
redirectTo: '/home'
});
// Setup route change error event
$rootScope.$on('$routeChangeError', function(event, current, previous, rejection) {
console.log('route-change-error');
});
// Setup route change start event
$rootScope.$on('$routeChangeStart', function(event, current, previous, rejection) {
console.log('route-change-start');
});
}]);
// Setup otherwise redirect
valent.config.exception.handler((exception, cause, $delegate) => {
console.log('exception');
});
// Setup otherwise redirect
valent.config.route.othwerwise('/home');
// Setup route change start event
valent.config.route.onChangeStart((event, current, previous, rejection) => {
console.log('route-change-start');
});
// Setup route change error event
valent.config.route.onChangeError((event, current, previous, rejection) => {
console.log('route-change-error');
});
// Add global resovler. Will be applied for each route.
valent.config.route.addResolver('permission', (name, params) => {
// ..
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment