{"id":8202,"date":"2017-10-08T22:07:21","date_gmt":"2017-10-08T13:07:21","guid":{"rendered":"http:\/\/www.webcyou.com\/?p=8202"},"modified":"2020-03-20T18:11:33","modified_gmt":"2020-03-20T09:11:33","slug":"angular4-ssr%ef%bc%88%e3%82%b5%e3%83%bc%e3%83%90%e3%83%bc%e3%82%b5%e3%82%a4%e3%83%89%e3%83%ac%e3%83%b3%e3%83%80%e3%83%aa%e3%83%b3%e3%82%b0%ef%bc%89%ef%bc%88universal-javascript%ef%bc%89%e7%92%b0","status":"publish","type":"post","link":"https:\/\/www.webcyou.com\/?p=8202","title":{"rendered":"Angular4 + SSR\uff08\u30b5\u30fc\u30d0\u30fc\u30b5\u30a4\u30c9\u30ec\u30f3\u30c0\u30ea\u30f3\u30b0\uff09\uff08Universal JavaScript\uff09\u74b0\u5883\u306e\u6700\u5c0f\u6700\u77ed \u69cb\u7bc9\u65b9\u6cd5"},"content":{"rendered":"<p>\u3069\u3082\u3067\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8218\" src=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/2017\/10\/angular_ssr.png\" alt=\"\" width=\"600\" height=\"300\" srcset=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/2017\/10\/angular_ssr.png 600w, https:\/\/www.webcyou.com\/wp-content\/uploads\/2017\/10\/angular_ssr-300x150.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<p>\u4eca\u56de\u306f\u3001Angular4\u3067\u6700\u5c0f\u306e<strong>SSR\uff08\u30b5\u30fc\u30d0\u30fc\u30b5\u30a4\u30c9\u30ec\u30f3\u30c0\u30ea\u30f3\u30b0 \u307e\u305f\u306f\u3001<\/strong>Universal JavaScript, \u30a2\u30a4\u30bd\u30e2\u30fc\u30d5\u30a3\u30c3\u30afJavaScript\uff09\u74b0\u5883\u306e\u69cb\u7bc9\u65b9\u6cd5\u3067\u3059\u3002<\/p>\n<h4>SSR\uff08\u30b5\u30fc\u30d0\u30fc\u30b5\u30a4\u30c9\u30ec\u30f3\u30c0\u30ea\u30f3\u30b0\uff09\u3068\u306f\u306a\u3093\u305e\u3084\u3002<\/h4>\n<p>SSR\uff08\u30b5\u30fc\u30d0\u30fc\u30b5\u30a4\u30c9\u30ec\u30f3\u30c0\u30ea\u30f3\u30b0 \u307e\u305f\u306f\u3001<strong>Universal JavaScript<\/strong>, <strong>\u30a2\u30a4\u30bd\u30e2\u30fc\u30d5\u30a3\u30c3\u30afJavaScript<\/strong>\uff09\u3068\u306f\u3001\u3056\u3063\u304f\u308a\u8a00\u3046\u3068\u3001\u521d\u671f\u8868\u793a\u3092\u30b5\u30fc\u30d0\u30fc\u5074\uff08\u4eca\u56de\u306fexpress\u3092\u4f7f\u7528\uff09\u3067\u8868\u793a\u3055\u305b\u3001\u305d\u306e\u5f8c\u306f\u901a\u5e38\u306erouting\u3092\u7528\u3044\u305fSPA\u306e\u51e6\u7406\u3092\u884c\u3046\u624b\u6cd5\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u4f55\u304c\u5b09\u3057\u3044\u304b\u3068\u8a00\u3046\u3068\u3001\u6700\u3082\u5f97\u3089\u308c\u308b\u52b9\u679c\u3068\u3057\u3066\u306f<\/p>\n<p><strong>\u30fb\u521d\u671f\u8868\u793a\u306eHTML\u306f\u30b5\u30fc\u30d0\u30fc\u5074\u3067\u751f\u6210\u3059\u308b\u306e\u3067\u3001\u9ad8\u901f\u5316\u3092\u56f3\u308c\u308b\u3002<\/strong><\/p>\n<p><strong>\u30fb\u30d5\u30e9\u30b0\u30e1\u30f3\u30c8\u8b58\u5225\u5b50\u306e\u5fc5\u8981\u6027\u304c\u306a\u3044\u306e\u3067\u3001SEO\u5bfe\u7b56\u3068\u306a\u308b\u3002<\/strong><\/p>\n<p>etc..\uff08\u4ed6\u306b\u3082\u3042\u308a\u307e\u3059\u304c\uff09<\/p>\n<p>\u3068\u3001\u8a00\u3063\u305f\u3068\u3053\u308d\u3067\u3057\u3087\u3046\u304b\u3002<\/p>\n<p>\u5f53\u65b9\u3082\u4ee5\u524d\u3001angularJS\u3067\u30b2\u30fc\u30e0\u4f5c\u6210\u3057\u3066\u3044\u305f\u9803\uff08\u4eca\u306f\u3001\u3082\u3063\u3071\u3089VueJS\uff09\u3001\u3053\u3093\u306a\u611f\u3058\u3067\u521d\u671f\u8868\u793a\u306fDOM\u306e\u65b9\u306bjson\u3092\u51fa\u529b\u3057\u3001\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3092\u7a3c\u3044\u3067\u304a\u308a\u307e\u3057\u305f\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">var json = JSON.parse(apiPath);\r\nangular.element(document).ready(function () {\r\n  Homepage.app.value('data', json.data);\r\n  angular.bootstrap(document, &#x5B;'Homepage'])\r\n});<\/pre>\n<p>PC\u30b5\u30a4\u30c8\u3060\u3068\u6c17\u306b\u306a\u3089\u306a\u3044\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u304c\u3001\u30b9\u30de\u30fc\u30c8\u30d5\u30a9\u30f3\u3068\u306a\u308b\u3068\u56de\u7dda\u3082\u65e9\u304f\u306a\u3044\u5834\u5408\u3082\u3042\u308a\u307e\u3059\u306e\u3067\u3001\u521d\u671f\u8868\u793a\u306e\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3084\u30ec\u30b9\u30dd\u30f3\u30b9\u91cf\u306a\u3069\u306f\u91cd\u8981\u8996\u3055\u308c\u3066\u3044\u307e\u3057\u305f\u3002<\/p>\n<p>\u306a\u306e\u3067\u3001\u4e0a\u8a18\u306e\u65b9\u6cd5\u7b49\u3067\u56de\u907f\u3057\u3066\u3044\u305f\u3053\u3068\u3082\u3042\u308a\u307e\u3057\u305f\u3002<\/p>\n<p>\u3068\u8a00\u3063\u305f\u611f\u3058\u306b\u3001<strong>SSR\uff08\u30b5\u30fc\u30d0\u30fc\u30b5\u30a4\u30c9\u30ec\u30f3\u30c0\u30ea\u30f3\u30b0 \u307e\u305f\u306f\u3001<\/strong>Universal JavaScript, \u30a2\u30a4\u30bd\u30e2\u30fc\u30d5\u30a3\u30c3\u30afJavaScript\uff09\u5468\u308a\u306e\u4e8b\u3092\u66f8\u304d\u51fa\u3059\u3068\u30ad\u30ea\u304c\u306a\u3044\u304b\u3068\u601d\u3044\u307e\u3059\u306e\u3067\u3001\u4eca\u56de\u306f\u8a73\u7d30\u306f\u66f8\u304b\u304d\u307e\u305b\u3093\u3002<\/p>\n<p>Google\u3055\u3093\u3067\u691c\u7d22\u306a\u3069\u3059\u308b\u3068\u3001\u8272\u3005\u3068\u898b\u3064\u304b\u308a\u307e\u3059\u306e\u3067\u8abf\u3079\u3066\u9802\u3051\u308c\u3070\u3068\u3002\uff1e\uff1c<\/p>\n<p>\u307e\u3041\u3001\u56f3\u3067\u8868\u3059\u3068\u4ee5\u4e0b\u306e\u69d8\u306b\u901a\u5e38\u306eSPA\u304b\u3089\u3001\u6700\u521d\u306e\u30ec\u30b9\u30dd\u30f3\u30b9\uff081,2\u306e\u624b\u9806\uff09\u3092\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u5074\u306b\u6301\u3063\u3066\u304f\u308b\u611f\u3058\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-8215\" src=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/2017\/10\/ssr-b.png\" alt=\"\" width=\"685\" height=\"251\" \/><\/p>\n<p>\u305d\u308c\u3067\u306f\u3001\u65e9\u901f\u69cb\u7bc9\u3057\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<h4>\u3059\u3050\u306b\u8a66\u3057\u305f\u3044\u65b9\u306f<\/h4>\n<p>\u3059\u3050\u306b\u52d5\u304b\u3057\u3066\u898b\u305f\u3044\u65b9\u306fgithub\u306e\u65b9\u306bup\u3057\u307e\u3057\u305f\u306e\u3067\u3001\u3053\u3061\u3089\u3092\u4f7f\u3063\u3066\u9802\u3051\u308c\u3070\u3068\u3002<\/p>\n<p><strong>Github<\/strong><\/p>\n<p><a href=\"https:\/\/github.com\/webcyou\/ang4-ssr\" target=\"_blank\" rel=\"noopener\">Angular 4 SSR (Universal) Starter<\/a><\/p>\n<h4>ng CLI\u3092\u7528\u3044\u305f\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u4f5c\u6210<\/h4>\n<p>\u4eca\u56de\u306f\u3001\u300c<strong>ng CLI<\/strong>\u300d\u3092\u7528\u3044\u3066\u74b0\u5883\u69cb\u7bc9\u3092\u884c\u3063\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<p>\u300c<strong>ng CLI<\/strong>\u300d\u3092\u3054\u5b58\u77e5\u3067\u306a\u3044\u65b9\u306f\u3001<a href=\"https:\/\/www.webcyou.com\/?p=7786\">\u3053\u3061\u3089<\/a>\u306e\u8a18\u4e8b\u306a\u3069\u3092\u53c2\u7167\u9802\u3051\u308c\u3070\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u300c<strong>ang4-ssr<\/strong>\u300d\u3068\u3044\u3046\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u540d\u3067\u751f\u6210\u3057\u307e\u3059\u3002<\/p>\n<p>\u30aa\u30d7\u30b7\u30e7\u30f3\u3067\u300crouting\u300d\u3092\u4ed8\u4e0e\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">ng new ang4-ssr --routing<\/pre>\n<p>\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u79fb\u52d5<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">cd ang4-ssr<\/pre>\n<p>\u305d\u306e\u4ed6\u3001\u5fc5\u8981\u306a\u30d1\u30c3\u30b1\u30fc\u30b8\u3092npm \u3067install\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">npm install --save @angular\/platform-server @angular\/animations<\/pre>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">npm\u00a0install --save-dev webpack<\/pre>\n<p>\u300capp.module.ts\u300d\u30d5\u30a1\u30a4\u30eb\u306e\u4e00\u90e8\u3092\u4fee\u6b63\u3057\u307e\u3059\u3002<\/p>\n<p><strong>src\/app\/app.module.ts<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">imports: &#x5B;\r\n  BrowserModule,\r\n  ...\r\n],<\/pre>\n<p>\u2193<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">imports: &#x5B;\r\n  BrowserModule.withServerTransition({appId: 'ang4-ssr'}),\r\n  ...\r\n],<\/pre>\n<p>BrowserModule\u306ewithServerTransition\u30e1\u30f3\u30d0\u30fc\u3092\u5229\u7528\u3057\u307e\u3059\u3002<\/p>\n<h5>server.module\u4f5c\u6210<\/h5>\n<p>\u65b0\u898f\u3067\u300capp.server.module.ts\u300d\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<p>\u300c@angular\/platform-server\u300d\u30d1\u30c3\u30b1\u30fc\u30b8\u306e\u300cServerModule\u300d\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<\/p>\n<p>\u3053\u308c\u3092\u300cNgModule\u300d\u306bimport\u3059\u308b\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<p><strong>src\/app\/app.server.module.ts<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">import { NgModule } from '@angular\/core';\r\nimport { ServerModule } from '@angular\/platform-server';\r\nimport { AppModule } from '.\/app.module';\r\nimport { AppComponent } from '.\/app.component';\r\n\r\n@NgModule({\r\nimports: &#x5B;\r\n  ServerModule,\r\n  AppModule\r\n],\r\nbootstrap: &#x5B;AppComponent]\r\n})\r\nexport class AppServerModule { }<\/pre>\n<h5>server.ts\u30d5\u30a1\u30a4\u30eb\u4f5c\u6210<\/h5>\n<p>\u65b0\u898f\u306b\u300cserver.ts\u300d\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<p>\u300c@angular\/platform-server\u300d\u30d1\u30c3\u30b1\u30fc\u30b8\u304b\u3089\u3001\u300cplatformServer, renderModuleFactory\u300d\u3068\u305d\u308c\u305e\u308c\u306e\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<\/p>\n<p>\u30b5\u30fc\u30d0\u30fc\u306f\u300cexpress\u300d\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<\/p>\n<p><strong>src\/server.ts<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">import 'reflect-metadata';\r\nimport 'zone.js\/dist\/zone-node';\r\nimport { platformServer, renderModuleFactory } from '@angular\/platform-server';\r\nimport { enableProdMode } from '@angular\/core';\r\nimport { AppServerModuleNgFactory } from '..\/dist\/ngfactory\/src\/app\/app.server.module.ngfactory';\r\nimport * as express from 'express';\r\nimport { readFileSync } from 'fs';\r\nimport { join } from 'path';\r\n\r\nconst PORT = 4000;\r\n\r\nenableProdMode();\r\n\r\nconst app = express();\r\n\r\nconst template = readFileSync(join(__dirname, '..', 'dist', 'index.html')).toString();\r\n\r\napp.engine('html', (_, options, callback) =&gt; {\r\n  const opts = { document: template, url: options.req.url };\r\n\r\n  renderModuleFactory(AppServerModuleNgFactory, opts)\r\n    .then(html =&gt; callback(null, html));\r\n});\r\n\r\napp.set('view engine', 'html');\r\napp.set('views', 'src');\r\n\r\napp.get('*.*', express.static(join(__dirname, '..', 'dist')));\r\n\r\napp.get('*', (req, res) =&gt; {\r\n  res.render('index', { req });\r\n});\r\n\r\napp.listen(PORT, () =&gt; {\r\n  console.log(`listening on http:\/\/localhost:${PORT}!`);\r\n});<\/pre>\n<p>\u30ec\u30f3\u30c0\u30ea\u30f3\u30b0\u3092\u884c\u3046\u30d5\u30a1\u30a4\u30eb\u306f\u3001dist\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u53c2\u7167\u3059\u308b\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<p>\u307e\u305f\u3001AppServerModuleNgFactory\u30e2\u30b8\u30e5\u30fc\u30eb\u304c\u5b58\u5728\u3057\u306a\u3044\u72b6\u614b\u306a\u306e\u3067\u3001\u4ee5\u4e0b\u306e\u69d8\u306bPATH\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u307e\u3059\u306e\u3067\u3001\u30d3\u30eb\u30c9\u3092\u884c\u3048\u308b\u3088\u3046\u306b\u8a2d\u5b9a\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8208\" src=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/2017\/10\/49f46c569ebf2bf477e3e7e6961cdc13.png\" alt=\"\" width=\"698\" height=\"24\" srcset=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/2017\/10\/49f46c569ebf2bf477e3e7e6961cdc13.png 698w, https:\/\/www.webcyou.com\/wp-content\/uploads\/2017\/10\/49f46c569ebf2bf477e3e7e6961cdc13-300x10.png 300w\" sizes=\"auto, (max-width: 698px) 100vw, 698px\" \/><\/p>\n<h5>tsconfig.app.json\u8ffd\u52a0\u4fee\u6b63<\/h5>\n<p>tsconfig.app.json\u306e&#8221;exclude&#8221;\u306b\u300c&#8221;server.ts&#8221;\u300d\u8ffd\u52a0\u4fee\u6b63\u884c\u3044\u307e\u3059\u3002<\/p>\n<p><strong>src\/tsconfig.app.json<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\"exclude\": &#x5B;\r\n  \"test.ts\",\r\n  \"**\/*.spec.ts\"\r\n]<\/pre>\n<p>\u2193<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\"exclude\": &#x5B;\r\n  \"server.ts\",\r\n  \"test.ts\",\r\n  \"**\/*.spec.ts\"\r\n]<\/pre>\n<h5>tsconfig.json\u9805\u76ee\u8ffd\u52a0<\/h5>\n<p>tsconfig.json\u30d5\u30a1\u30a4\u30eb\u306b\u300c&#8221;angularCompilerOptions&#8221;\u300d\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<p>compilerOptions\u3068\u540c\u5217\u306b\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<p><strong>\/tsconfig.json<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\"angularCompilerOptions\": {\r\n  \"genDir\": \".\/dist\/ngfactory\",\r\n  \"entryModule\": \".\/src\/app\/app.module#AppModule\"\r\n}<\/pre>\n<h5>package.json\u3001scripts\u4fee\u6b63<\/h5>\n<p>package.json\u306escripts\u306b\u30c7\u30d5\u30a9\u30eb\u30c8\u306e\u30b3\u30de\u30f3\u30c9\u304c\u8a18\u8ff0\u3055\u308c\u3066\u3044\u307e\u3059\u304c\u3001\u3053\u308c\u3089\u3092\u5909\u66f4\u3057\u307e\u3059\u3002<\/p>\n<p><strong>\/package.json<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\"scripts\": {\r\n  \"ng\": \"ng\",\r\n  \"start\": \"ng serve\",\r\n  \"build\": \"ng build\",\r\n  \"test\": \"ng test\",\r\n  \"lint\": \"ng lint\",\r\n  \"e2e\": \"ng e2e\"\r\n},<\/pre>\n<p>\u2193<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\"scripts\": {\r\n  \"prestart\": \"ng build --prod &amp;&amp; ngc\",\r\n  \"start\": \"ts-node src\/server.ts\"\r\n},<\/pre>\n<p>\u3068\u3001\u4e00\u65e6\u3053\u3053\u307e\u3067\u4fee\u6b63\u5b8c\u4e86\u3057\u307e\u3057\u305f\u3089\u3001\u8d77\u52d5\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">npm run start<\/pre>\n<p>express\u30b5\u30fc\u30d0\u30fc\u304c\u8d77\u52d5\u3057\u3066\u3001\u554f\u984c\u304c\u306a\u3051\u308c\u3070\u3001localhost\u306e4000\u756a\u30dd\u30fc\u30c8\u3067\u3001\u30b5\u30fc\u30d0\u304c\u7acb\u3061\u4e0a\u304c\u308a\u307e\u3059\u3002<\/p>\n<p>\u30d6\u30e9\u30a6\u30b6\u3067\u300chttp:\/\/localhost:4000\u300d\u3092\u30a2\u30af\u30bb\u30b9\u3057\u307e\u3059\u3002<\/p>\n<p><a href=\"http:\/\/localhost:4000\" target=\"_blank\" rel=\"noopener\">http:\/\/localhost:4000<\/a><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-8207\" src=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/2017\/10\/2863773ef46e6f3b0ce9a1c09e9d86dd.png\" alt=\"\" width=\"260\" height=\"276\" srcset=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/2017\/10\/2863773ef46e6f3b0ce9a1c09e9d86dd.png 359w, https:\/\/www.webcyou.com\/wp-content\/uploads\/2017\/10\/2863773ef46e6f3b0ce9a1c09e9d86dd-283x300.png 283w\" sizes=\"auto, (max-width: 260px) 100vw, 260px\" \/><\/p>\n<p>\u4e0a\u8a18\u306e\u69d8\u306b\u78ba\u8a8d\u3067\u304d\u308c\u3070\u30aa\u30c3\u30b1\u30fc\u3067\u3059\u3002<\/p>\n<h4>ng \u30b8\u30a7\u30cd\u30ec\u30fc\u30c8\u30b3\u30de\u30f3\u30c9\u3067\u3001\u30da\u30fc\u30b8\u4f5c\u6210<\/h4>\n<p>\u305d\u308c\u3067\u306f\u3001\u30da\u30fc\u30b8\u304c\u5909\u308f\u308b\u3068meta\u304c\u5909\u66f4\u51fa\u6765\u308b\u3088\u3046\u306b\u4fee\u6b63\u3057\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>ctrl + c \u7b49\u3067\u3001\u4e00\u65e6\u30b5\u30fc\u30d0\u30fc\u3092\u6b62\u3081\u3066\u3001\u300c<strong>ng generate<\/strong>\u300d\u30b3\u30de\u30f3\u30c9\u3067\u30da\u30fc\u30b8\u4f5c\u6210\u306e\u4e00\u5f0f\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">ng g c home --module=app.module.ts<\/pre>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">ng g c\u00a0about --module=app.module.ts<\/pre>\n<p>\u300c<strong>ng generate<\/strong>\u300d\u30b3\u30de\u30f3\u30c9\u3067\u300cabout\u300d\u300chome\u300d\u3092\u4f5c\u6210\u3057\u305f\u3068\u3053\u308d\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-8209\" src=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/2017\/10\/4b899393e651e7f10fa3c3f6f3e63e3a.png\" alt=\"\" width=\"225\" height=\"175\" \/><\/p>\n<h5>app-routing.module.ts\u30d5\u30a1\u30a4\u30eb\u8ffd\u52a0\u4fee\u6b63<\/h5>\n<p>app-routing.module.ts\u306b\u8ffd\u52a0\u4fee\u6b63\u3092\u884c\u3063\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<p>\u5148\u7a0b\u3001\u300c<strong>ng generate<\/strong>\u300d\u30b3\u30de\u30f3\u30c9\u3067\u751f\u6210\u3057\u305f\u300cabout\u300d\u300chome\u300d\u306ecomponent\u3092import\u3057\u3001\u30eb\u30fc\u30c6\u30a3\u30f3\u30b0\u306b\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<p><strong>app-routing.module.ts<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">import { NgModule } from '@angular\/core';\r\nimport { Routes, RouterModule } from '@angular\/router';\r\nimport { AboutComponent } from '.\/about\/about.component';\r\nimport { HomeComponent } from '.\/home\/home.component';\r\n\r\nconst routes: Routes = &#x5B;\r\n  {\r\n    path: '',\r\n    component: HomeComponent\r\n  },\r\n  {\r\n    path: 'about',\r\n    component: AboutComponent\r\n  }\r\n];\r\n\r\n@NgModule({\r\n  imports: &#x5B;RouterModule.forRoot(routes)],\r\n  exports: &#x5B;RouterModule]\r\n})\r\nexport class AppRoutingModule { }<\/pre>\n<h5>app.component.html\u4fee\u6b63<\/h5>\n<p>\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u306f\u3001app.component.html\u306b\u8272\u3005\u3068\u8a18\u8ff0\u3055\u308c\u3066\u3044\u307e\u3059\u304c\u3001\u524a\u9664\u3057\u3066\u30da\u30fc\u30b8\u9077\u79fb\u51fa\u6765\u308b\u3088\u3046\u306b\u4fee\u6b63\u3057\u307e\u3059\u3002<\/p>\n<p><strong>app.component.html<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">&lt;ul&gt;\r\n \t&lt;li&gt;&lt;a&gt;Home&lt;\/a&gt;&lt;\/li&gt;\r\n \t&lt;li&gt;&lt;a&gt;About&lt;\/a&gt;&lt;\/li&gt;\r\n&lt;\/ul&gt;<\/pre>\n<h5>home.component.ts\u4fee\u6b63<\/h5>\n<p>home.component.ts\u3092\u4fee\u6b63\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<p>&#8216;@angular\/platform-browser&#8217;\u30d1\u30c3\u30b1\u30fc\u30b8\u306e\u300cMeta\u300d\u3068\u300cTitle\u300d\u3092import\u3057\u307e\u3059\u3002<\/p>\n<p>\u3053\u308c\u3089\u306f\u305d\u308c\u305e\u308c\u3001Title\u3084meta\u3092\u6271\u3046\u305f\u3081\u306eAPI\u304c\u7528\u610f\u3055\u308c\u3066\u3044\u308b\u306e\u3067\u3001\u3053\u3061\u3089\u3092\u7528\u3044\u3066Title\u3084meta\u3092\u5909\u66f4\u51fa\u6765\u308b\u69d8\u306b\u8a2d\u5b9a\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<p>description\u304c\u5897\u3048\u7d9a\u3051\u306a\u3044\u69d8\u306b\u3001meta.removeTag\u3067\u4e00\u65e6\u521d\u671f\u5316\u3092\u884c\u3044\u3001\u8ffd\u52a0\u3057\u3066\u304a\u308a\u307e\u3059\u3002<\/p>\n<p><strong>src\/app\/home\/home.component.ts<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">import { Component, OnInit } from '@angular\/core';\r\nimport { Meta, Title } from '@angular\/platform-browser';\r\n\r\n@Component({\r\n  selector: 'app-home',\r\n  templateUrl: '.\/home.component.html',\r\n  styleUrls: &#x5B;'.\/home.component.css']\r\n})\r\nexport class HomeComponent implements OnInit {\r\n\r\n  constructor(meta: Meta, title: Title) {\r\n\r\n    title.setTitle('Angular4 SSR');\r\n\r\n    meta.removeTag('name=description');\r\n\r\n    meta.addTags(&#x5B;\r\n      {\r\n        name: 'author', content: 'webcyou.com'\r\n      },\r\n      {\r\n        name: 'keywords', content: 'Angular 4 SSR tutorial'\r\n      },\r\n      {\r\n        name: 'description', content: 'Angular4\u306eSSR\u74b0\u5883\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u3067\u3059'\r\n      },\r\n    ]);\r\n\r\n  }\r\n\r\n  ngOnInit() {\r\n  }\r\n\r\n}<\/pre>\n<h5>about.component.ts\u4fee\u6b63<\/h5>\n<p>\u540c\u69d8\u306babout.component.ts\u3092\u4fee\u6b63\u3057\u307e\u3059\u3002<\/p>\n<p>\u3053\u3061\u3089\u3067\u306f\u3001title.setTitle(&#8216;Angular4 SSR &#8211; about\u30da\u30fc\u30b8&#8217;)\u3068\u3001description\u304c\u5909\u66f4\u51fa\u6765\u308b\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<p><strong>src\/app\/about\/about.component.ts<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">import { Component, OnInit } from '@angular\/core';\r\nimport { Meta, Title } from '@angular\/platform-browser';\r\n\r\n@Component({\r\n  selector: 'app-about',\r\n  templateUrl: '.\/about.component.html',\r\n  styleUrls: &#x5B;'.\/about.component.css']\r\n})\r\nexport class AboutComponent implements OnInit {\r\n\r\n  constructor(meta: Meta, title: Title) {\r\n\r\n    title.setTitle('Angular4 SSR - about\u30da\u30fc\u30b8');\r\n\r\n    meta.removeTag('name=description');\r\n\r\n    meta.addTags(&#x5B;\r\n      {\r\n        name: 'description', content: 'about\u30da\u30fc\u30b8\u306edescription'\r\n      },\r\n    ]);\r\n\r\n  }\r\n\r\n  ngOnInit() {\r\n  }\r\n\r\n}<\/pre>\n<p>\u3068\u3001\u3053\u308c\u3067\u3001\u5b8c\u4e86\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u305d\u308c\u3067\u306f\u3001\u78ba\u8a8d\u3057\u3066\u3044\u304d\u307e\u3057\u3087\u3046\uff01<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">npm start<\/pre>\n<p>\u30d6\u30e9\u30a6\u30b6\u3067\u300chttp:\/\/localhost:4000\u300d\u3092\u30a2\u30af\u30bb\u30b9\u3057\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8212\" src=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/2017\/10\/eaf7220f68cf34342d9d71cc41abe023.png\" alt=\"\" width=\"118\" height=\"68\" \/><\/p>\n<p>\u5404\u30ea\u30f3\u30af\u3092\u30af\u30ea\u30c3\u30af\u3059\u308b\u3068\u5404\u30da\u30fc\u30b8\u3078\u3068\u9077\u79fb\u304c\u3067\u304d\u3001\u78ba\u8a8d\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>web\u30a4\u30f3\u30b9\u30da\u30af\u30bf\u7b49\u3067\u3001meta\u3092\u78ba\u8a8d<\/p>\n<p><strong>Home\u30da\u30fc\u30b8<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-8210\" src=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/2017\/10\/ab5dde3b7b673c813579b3c5628d2ba3.png\" alt=\"\" width=\"454\" height=\"134\" srcset=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/2017\/10\/ab5dde3b7b673c813579b3c5628d2ba3.png 478w, https:\/\/www.webcyou.com\/wp-content\/uploads\/2017\/10\/ab5dde3b7b673c813579b3c5628d2ba3-300x88.png 300w\" sizes=\"auto, (max-width: 454px) 100vw, 454px\" \/><\/p>\n<p><strong>About\u30da\u30fc\u30b8<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-8211\" src=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/2017\/10\/626fc2baf4dd09467501e6d62930d608.png\" alt=\"\" width=\"463\" height=\"153\" srcset=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/2017\/10\/626fc2baf4dd09467501e6d62930d608.png 475w, https:\/\/www.webcyou.com\/wp-content\/uploads\/2017\/10\/626fc2baf4dd09467501e6d62930d608-300x99.png 300w\" sizes=\"auto, (max-width: 463px) 100vw, 463px\" \/><\/p>\n<p>meta\u30bf\u30b0\u304c\u5909\u66f4\u3057\u3066\u3044\u308b\u306e\u304c\u78ba\u8a8d\u3067\u304d\u307e\u3057\u305f\uff01<\/p>\n<h4>\u6700\u5f8c\u306b<\/h4>\n<p>\u3068\u8a00\u3063\u305f\u611f\u3058\u3067\u3001Angular4\u3067\u6700\u5c0f\u306e<strong>SSR\uff08\u30b5\u30fc\u30d0\u30fc\u30b5\u30a4\u30c9\u30ec\u30f3\u30c0\u30ea\u30f3\u30b0 \u307e\u305f\u306f\u3001<\/strong>Universal JavaScript, \u30a2\u30a4\u30bd\u30e2\u30fc\u30d5\u30a3\u30c3\u30afJavaScript\uff09\u74b0\u5883\u306e\u69cb\u7bc9\u65b9\u6cd5\u3067\u3057\u305f\u3002<\/p>\n<p>Angular4\u306f\u30d5\u30eb\u30b9\u30da\u30c3\u30af\u306a\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u306a\u6545\u306b\u5bb9\u91cf\u3082\u5927\u304d\u3044\u3068\u3053\u308d\u304c\u3042\u308a\u307e\u3059\u304c\u3001\u30d1\u30c3\u30b1\u30fc\u30b8\u306a\u3069\u3082\u516c\u5f0f\u3067\u63c3\u3063\u3066\u3044\u308b\u70b9\u304b\u3089\u300c\u4e00\u3064\u4e00\u3064\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u9078\u629e\u3059\u308b\u300d\u3068\u8a00\u3063\u305f\u624b\u9806\u3082\u6e1b\u308b\u3053\u3068\u304b\u3089\u3001\u6bd4\u8f03\u7684\u7c21\u5358\u306b\u74b0\u5883\u3092\u69cb\u7bc9\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u70b9\u304c\u826f\u304b\u3063\u305f\u308a\u3057\u307e\u3059\u306d\u3002<\/p>\n<p>\u4eca\u56de\u306e\u30bd\u30fc\u30b9\u306f\u3053\u3061\u3089\u306b\u3042\u308a\u307e\u3059\u306e\u3067\u3001\u5b9c\u3057\u3051\u308c\u3070\u3068\u3002<\/p>\n<p><strong>Github<\/strong><\/p>\n<p><a href=\"https:\/\/github.com\/webcyou\/ang4-ssr\" target=\"_blank\" rel=\"noopener\">Angular 4 SSR (Universal) Starter<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>\u3067\u306f\u3067\u306f\u3041\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3069\u3082\u3067\u3059\u3002 \u4eca\u56de\u306f\u3001Angular4\u3067\u6700\u5c0f\u306eSSR\uff08\u30b5\u30fc\u30d0\u30fc\u30b5\u30a4\u30c9\u30ec\u30f3\u30c0\u30ea\u30f3\u30b0 \u307e\u305f\u306f\u3001Universal JavaScript, \u30a2\u30a4\u30bd\u30e2\u30fc\u30d5\u30a3\u30c3\u30afJavaScript\uff09\u74b0\u5883\u306e\u69cb\u7bc9\u65b9\u6cd5\u3067\u3059\u3002 SSR\uff08\u30b5\u30fc\u30d0\u30fc\u30b5\u30a4\u30c9\u30ec\u30f3 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[203],"tags":[171,59,167,177,168,176,40,166,37,47,179,50,46,169,107,180,44,45,111,95,39,178,138,78,114,118],"class_list":{"0":"post-8202","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"hentry","6":"category-angular2","7":"tag-android","8":"tag-android-sdk","9":"tag-css","10":"tag-css3","11":"tag-html","12":"tag-html5","13":"tag-ios-sdk","14":"tag-iphone","15":"tag-iphone-","16":"tag-javascript-2","17":"tag-jquery","18":"tag-jquery-mobile","19":"tag-js","20":"tag-mac","21":"tag-mamp","22":"tag-mysql","23":"tag-web","25":"tag-wordpress-2","26":"tag-95","27":"tag-39","28":"tag-178","29":"tag-138","30":"tag-78","31":"tag-114","32":"tag-118"},"_links":{"self":[{"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/posts\/8202","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=8202"}],"version-history":[{"count":11,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/posts\/8202\/revisions"}],"predecessor-version":[{"id":10191,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/posts\/8202\/revisions\/10191"}],"wp:attachment":[{"href":"https:\/\/www.webcyou.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=8202"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=8202"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=8202"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}