8
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

AngularJSのhtmlModeを使いこなす

8
Last updated at Posted at 2014-10-26

htmlModeを使えばexample.com/#/aaとなっているのをexample.com/aaととてもシンプルにすることができます。
しかし、これをリロードしようとすると、/aaにGETしてしまいます。
対処方法としてはバックエンドのフレームワークで問答無用で同じhtmlを返す事でしょうか…

app.coffee
app = angular
  .module "app", ["ngRoute"]
  .config ($routeProvider, $locationProvider) ->
    $locationProvider.html5Mode true
    $routeProvider
      .when "/",
        templateUrl: "/templates/app.html"
        controller: "IndexCtrl"
      .otherwise
        redirectTo: "/"
    return
  .controller "IndexCtrl", ($scope, $http) ->
    console.log "hhh"
index.html
<body>
    <base href="/"/>
    <div ng-app="app" class="app_route" ng-view></div>
</body>

baseタグがないと動かないようです。

routerにSinatraやExpressを使って、どのルーティングでもindex.htmlを書くように書いたら動きそう

--追記--
Nginxのrewrite使っても良さそう

8
8
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
8
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?