LoginSignup
13
13

More than 1 year has passed since last update.

ui-router で 404 ページを表示する

Last updated at Posted at 2014-09-21

templateUrl に 404 ページを設定したステートを作成し、otherwise に設定したハンドラで $state.go メソッドを使って 404 ページを表示する。

$urlRouterProvider.otherwise を使わず $rootScope.$on("$stateChangeError") のハンドラで行ってもよいと思う。

angular.module("myapp").config(function ($stateProvider, $urlRouterProvider) {
  $stateProvider
      .state("404", {
        templateUrl: "/views/404.html"
      });

  $urlRouterProvider
    .otherwise(function ($injector) {
      $injector.get("$state").go("404");
    });
});
13
13
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
13