{"id":1063,"date":"2015-07-30T05:18:35","date_gmt":"2015-07-30T05:18:35","guid":{"rendered":"http:\/\/www.honobono-life.info\/wpeng\/?p=1063"},"modified":"2015-07-30T05:18:35","modified_gmt":"2015-07-30T05:18:35","slug":"angularjs-route-default-route","status":"publish","type":"post","link":"http:\/\/www.honobono-life.info\/wpeng\/angularjs-route-default-route\/","title":{"rendered":"Ruby on Rails Tutorial\u3000AngularJS, route, default route"},"content":{"rendered":"<p><strong>1)AnguraJS route<\/strong><\/p>\r\n\r\n<p><strong>1.angular-route include<\/strong><\/p>\r\n\r\n<p>$ vi app\/assets\/javascripts\/application.js<\/p>\r\n\r\n<p>\/\/= require angular-route<\/p>\r\n\r\n<p><strong>2.ngRoute DI<\/strong><\/p>\r\n\r\n<p>$ vi app\/assets\/javascripts\/mymodule.js<\/p>\r\n\r\n<p>myModule = angular.module(&#39;myModule&#39;, [&#39;ui.bootstrap&#39;,&#39;ngRoute&#39;]);<\/p>\r\n\r\n<p><strong>2)$routeProvider<\/strong><\/p>\r\n\r\n<p>$ vi app\/assets\/javascripts\/mymodule.js.erb<\/p>\r\n\r\n<pre class=\"prettyprint\">\r\nmyModule = angular.module(&#39;myModule&#39;, [&#39;ui.bootstrap&#39;,&#39;ngRoute&#39;]);\r\n\r\nmyModule.config(function($routeProvider, $locationProvider) {\r\n  $locationProvider.html5Mode(true);\r\n  $routeProvider\r\n    .when(&quot;\/static_pages\/help&quot;, {\r\n     templateUrl: &quot;&lt;%= asset_path(&#39;static_pages\/help.html.erb&#39;) %&gt;&quot;\r\n     })\r\n    .when(&quot;\/static_pages\/about&quot;, {\r\n     templateUrl: &quot;&lt;%= asset_path(&#39;static_pages\/about.html.erb&#39;) %&gt;&quot;\r\n     })\r\n    .when(&quot;\/static_pages\/contact&quot;, {\r\n     templateUrl: &quot;&lt;%= asset_path(&#39;static_pages\/contact.html.erb&#39;) %&gt;&quot;\r\n     })\r\n    .otherwise({\r\n     templateUrl: &quot;&lt;%= asset_path(&#39;static_pages\/home.html.erb&#39;) %&gt;&quot;\r\n     });\r\n});<\/pre>\r\n\r\n<p><strong>3)AngularJS templates<\/strong><\/p>\r\n\r\n<p>$ vi app\/assets\/templates\/static_pages\/home.html.erb<\/p>\r\n\r\n<p>&lt;h2&gt;Home&lt;\/h2&gt;<\/p>\r\n\r\n<p>$ vi app\/assets\/templates\/static_pages\/about.html.erb<\/p>\r\n\r\n<p>&lt;h2&gt;About&lt;\/h2&gt;<\/p>\r\n\r\n<p>$ vi app\/assets\/templates\/static_pages\/help.html.erb<\/p>\r\n\r\n<p>&lt;h2&gt;Help&lt;\/h2&gt;<\/p>\r\n\r\n<p>$ vi app\/assets\/templates\/static_pages\/contact.html.erb<\/p>\r\n\r\n<p>&lt;h2&gt;Contact&lt;\/h2&gt;<\/p>\r\n\r\n<p><strong>4)AngularJS ng-view<\/strong><\/p>\r\n\r\n<p>$ vi app\/views\/layouts\/application.html.erb<\/p>\r\n\r\n<pre class=\"prettyprint\">\r\n......\r\n  &lt;%= render &#39;layouts\/header&#39; %&gt;\r\n  &lt;div ng-view&gt;&lt;\/div&gt;\r\n  &lt;%= render &#39;layouts\/footer&#39; %&gt;\r\n.....<\/pre>\r\n\r\n<p><strong>5)Rails route<\/strong><\/p>\r\n\r\n<p><strong>1.Rails layouts_controller, config\/routes.rb<\/strong><\/p>\r\n\r\n<p>$ vi app\/controllers\/layouts_controller.rb<\/p>\r\n\r\n<pre class=\"prettyprint\">\r\nclass LayoutsController &lt; ApplicationController\r\n  def index\r\n    render &quot;layouts\/application&quot;\r\n  end\r\nend<\/pre>\r\n\r\n<p>$ vi config\/routes.rb<br \/>\r\n&nbsp; root &#39;layouts#index&#39;<\/p>\r\n\r\n<p><strong>2.default route<\/strong><\/p>\r\n\r\n<p>$ vi config\/routes.rb<br \/>\r\n&nbsp; get &#39;static_pages\/*other&#39;, to: &#39;layouts#index&#39;<\/p>\r\n\r\n<p><strong>6)AngularJS $location, html5 mode, &lt;base&gt; tag<\/strong><\/p>\r\n\r\n<p>$ vi app\/views\/layouts\/application.html.erb<\/p>\r\n\r\n<pre class=\"prettyprint\">\r\n&lt;head&gt;\r\n.....\r\n  &lt;base href=&quot;\/&quot;&gt;\r\n&lt;\/head&gt;<\/pre>\r\n\r\n<p><strong>7)test operation<\/strong><\/p>\r\n\r\n<p>http:\/\/localhost:3000\/static_pages\/help<br \/>\r\nhttp:\/\/localhost:3000\/static_pages\/about<br \/>\r\nhttp:\/\/localhost:3000\/static_pages\/contact<\/p>\r\n","protected":false},"excerpt":{"rendered":"<p>1)AnguraJS route 1.angular-route include $ vi app\/assets\/javascripts\/application.js \/\/= require angular-route 2.ngRoute DI $ vi app\/assets\/javascripts\/mymodule.js myModule = angular.module(&#39;myModule&#39;, [&#39;ui.bootstrap&#39;,&#39;ngRoute&#39;]); 2)$routeProvider $ vi app\/assets\/javascripts\/mymodule.js.erb myModule = angular.module(&#39;myModule&#39;, [&#39;ui.bootstrap&#39;,&#39;ngRoute&#39;]); myModule.config(function($routeProvider, $locationProvider) { $locationProvider.html5Mode(true); $routeProvider .when(&quot;\/static_pages\/help&quot;, { templateUrl: &quot;&lt;%= asset_path(&#39;static_pages\/help.html.erb&#39;) %&gt;&quot; }) .when(&quot;\/static_pages\/about&quot;, { templateUrl: &quot;&lt;%= asset_path(&#39;static_pages\/about.html.erb&#39;) %&gt;&quot; }) .when(&quot;\/static_pages\/contact&quot;, { templateUrl: &quot;&lt;%= asset_path(&#39;static_pages\/contact.html.erb&#39;) %&gt;&quot; }) .otherwise({ templateUrl: [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[137],"tags":[35,142,143],"amp_enabled":true,"_links":{"self":[{"href":"http:\/\/www.honobono-life.info\/wpeng\/wp-json\/wp\/v2\/posts\/1063"}],"collection":[{"href":"http:\/\/www.honobono-life.info\/wpeng\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.honobono-life.info\/wpeng\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.honobono-life.info\/wpeng\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.honobono-life.info\/wpeng\/wp-json\/wp\/v2\/comments?post=1063"}],"version-history":[{"count":1,"href":"http:\/\/www.honobono-life.info\/wpeng\/wp-json\/wp\/v2\/posts\/1063\/revisions"}],"predecessor-version":[{"id":1064,"href":"http:\/\/www.honobono-life.info\/wpeng\/wp-json\/wp\/v2\/posts\/1063\/revisions\/1064"}],"wp:attachment":[{"href":"http:\/\/www.honobono-life.info\/wpeng\/wp-json\/wp\/v2\/media?parent=1063"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.honobono-life.info\/wpeng\/wp-json\/wp\/v2\/categories?post=1063"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.honobono-life.info\/wpeng\/wp-json\/wp\/v2\/tags?post=1063"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}