1
1

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.

reloadable html5Mode with yeoman/generator-angular

Posted at

Goal

html5Mode時に、/以外のパスでリロードしてもページが正しく表示される。

問題点

  • パスが/ではないので、リロードで404
  • jsファイルなどは相対パスで書かれているので404

解決策

html5Modeを有効化

app.config.js
angular
  .module('angularApp')
  .config(['$locationProvider', function($locationProvider) {
    $locationProvider.html5Mode(true);
  }]);

index.htmlへrewrite

stereokaiのsnippetをGruntfile.jsへ追加。

install connect-modrewrite

$ npm install --save-dev connect-modrewrite

base hrefを設定

index.html
<!doctype html>
<html class="no-js">
  <head>
    <base href="/">
1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?