Skip to content

Instantly share code, notes, and snippets.

@schmkr
Last active June 23, 2020 13:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save schmkr/896766d37877209c71fc to your computer and use it in GitHub Desktop.
Save schmkr/896766d37877209c71fc to your computer and use it in GitHub Desktop.
angular ui router 404 without redirect
angular.module("app.example", ["ui.router"])
.config(function($stateProvider, $urlRouterProvider) {
$stateProvider.state("404", {
templateUrl: "errors/notfound.tpl.html",
data: {
authorizationRequired: false,
permissionsRequired: [],
bodyClass: "error"
}
});
// show a not found error if route is unkown, but keep the original url
$urlRouterProvider.otherwise(function($injector) {
$injector.invoke(function($state) {
$state.transitionTo("404", {}, false);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment