﻿
{"id":9797,"date":"2018-10-29T22:33:54","date_gmt":"2018-10-29T22:33:54","guid":{"rendered":"http:\/\/www.gencayyildiz.com\/blog\/?p=9797"},"modified":"2018-10-29T22:33:54","modified_gmt":"2018-10-29T22:33:54","slug":"angular-6-multiple-router-outlet-kullanimi","status":"publish","type":"post","link":"https:\/\/www.gencayyildiz.com\/blog\/angular-6-multiple-router-outlet-kullanimi\/","title":{"rendered":"Angular 6 &#8211; Multiple Router Outlet Kullan\u0131m\u0131"},"content":{"rendered":"<div id=\"fb-root\"><\/div>\n<p>Merhaba,<\/p>\n<p>Single Page Application \u015feklinde nitelendirdi\u011fimiz web tabanl\u0131 uygulamalar geli\u015ftirmemizi sa\u011flayan Angular mimarisi, sayfa taleplerine cevap olarak component yap\u0131lar\u0131 ile kar\u015f\u0131l\u0131k verdi\u011finden dolay\u0131 uygulaman\u0131n bel kemi\u011fi tek bir router outlet&#8217;a ba\u011flanmakta ve son kullanc\u0131yla yap\u0131lan etkile\u015fimlerin b\u00fcy\u00fck \u00e7o\u011funlu\u011fu bu noktaya olan temasla neticelendirilmektedir. Bu makalemizde &#8220;<em>router outlet&#8217;e gelen bir component, i\u00e7erisinde farkl\u0131 y\u00f6nlendirmeler ve bunun yan\u0131nda farkl\u0131 router outlet bar\u0131nd\u0131rabilir mi?<\/em>&#8221; sorusuna kar\u015f\u0131l\u0131k &#8220;evet&#8221; cevab\u0131n\u0131 verecek ve bunun nas\u0131l sa\u011flanaca\u011f\u0131 \u00fczerine teknik boyutta detayl\u0131 bir izahatte bulunaca\u011f\u0131z.<\/p>\n<p>Tabi t\u00fcm olay\u0131 ad\u0131m ad\u0131m in\u015fa edilmi\u015f bir \u00e7al\u0131\u015fma \u00fczerinden senaryola\u015ft\u0131rarak izah etmeye \u00e7al\u0131\u015faca\u011f\u0131z.<\/p>\n<p>\u0130lk olarak bootstrap ve jquery k\u00fct\u00fcphanelerinin entegre edildi\u011fini varsayd\u0131\u011f\u0131m\u0131z bir Angular 6(<span style=\"font-size:10px;\">asl\u0131nda versiyon o kadar da \u00f6nemli de\u011fil<\/span>) projesi olu\u015fturuyoruz.<\/p>\n<p>Proje i\u00e7erisinde &#8220;Home&#8221;, &#8220;About&#8221;, &#8220;Contact&#8221; ve &#8220;Products&#8221; componentlerini olu\u015fturuyoruz.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nng g c home\r\nng g c about\r\nng g c contact\r\nng g c products\r\n<\/pre>\n<p>Ard\u0131ndan ana mod\u00fcl sayfam\u0131zda a\u015fa\u011f\u0131daki gibi route(rota) \u015femalar\u0131n\u0131 olu\u015fturup uygulamaya import ediyoruz.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nimport { BrowserModule } from '@angular\/platform-browser';\r\nimport { NgModule } from '@angular\/core';\r\n\r\nimport { AppComponent } from '.\/app.component';\r\nimport { HomeComponent } from '.\/home\/home.component';\r\nimport { AboutComponent } from '.\/about\/about.component';\r\nimport { ContactComponent } from '.\/contact\/contact.component';\r\nimport { ProductsComponent } from '.\/products\/products.component';\r\nimport { Route, RouterModule } from '@angular\/router';\r\n\r\nexport const appRoutes: Route&#x5B;] = &#x5B;\r\n  { path: '', redirectTo: '\/home', pathMatch: 'full' },\r\n  { path: 'home', component: HomeComponent },\r\n  { path: 'about', component: AboutComponent },\r\n  { path: 'contact', component: ContactComponent },\r\n  { path: 'products', component: ProductsComponent }\r\n];\r\n\r\n@NgModule({\r\n  declarations: &#x5B;\r\n    AppComponent,\r\n    HomeComponent,\r\n    AboutComponent,\r\n    ContactComponent,\r\n    ProductsComponent\r\n  ],\r\n  imports: &#x5B;\r\n    BrowserModule,\r\n    RouterModule.forRoot(appRoutes)\r\n  ],\r\n  providers: &#x5B;],\r\n  bootstrap: &#x5B;AppComponent]\r\n})\r\nexport class AppModule { }\r\n<\/pre>\n<p>Son olarak ana componentimizin g\u00f6r\u00fcnt\u00fcs\u00fc olan &#8220;app.component.html&#8221; dosyas\u0131nda a\u015fa\u011f\u0131daki gibi tasar\u0131m\u0131m\u0131z\u0131 in\u015fa ediyoruz.<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;ul class=&quot;nav&quot;&gt;\r\n  &lt;li class=&quot;nav-item&quot;&gt;\r\n    &lt;a class=&quot;nav-link active&quot; routerLink=&quot;home&quot;&gt;Home&lt;\/a&gt;\r\n  &lt;\/li&gt;\r\n  &lt;li class=&quot;nav-item&quot;&gt;\r\n    &lt;a class=&quot;nav-link&quot; routerLink=&quot;about&quot;&gt;About&lt;\/a&gt;\r\n  &lt;\/li&gt;\r\n  &lt;li class=&quot;nav-item&quot;&gt;\r\n    &lt;a class=&quot;nav-link&quot; routerLink=&quot;contact&quot;&gt;Contact&lt;\/a&gt;\r\n  &lt;\/li&gt;\r\n  &lt;li class=&quot;nav-item&quot;&gt;\r\n    &lt;a class=&quot;nav-link disabled&quot; routerLink=&quot;products&quot;&gt;Products&lt;\/a&gt;\r\n  &lt;\/li&gt;\r\n&lt;\/ul&gt;\r\n&lt;div&gt;\r\n  &lt;router-outlet&gt;&lt;\/router-outlet&gt;\r\n&lt;\/div&gt;\r\n<\/pre>\n<p>\u015eimdi bu noktaya kadar asl\u0131nda bildi\u011fimiz Angular&#8217;da route i\u015flemlerini ger\u00e7ekle\u015ftirdik ve yap\u0131lan talepler neticesinde url&#8217;de ki adrese g\u00f6re ilgili componenti y\u00f6nlendirmede bulunmu\u015f olduk.<\/p>\n<p>\u0130\u015fte bu noktadan itibaren &#8220;Products&#8221; isimli componentimiz i\u00e7erisinde birden fazla product&#8217;a olan y\u00f6nlendirmeler i\u00e7in de bir route outlet tan\u0131mlayal\u0131m. Tabi \u00f6ncelikle birden fazla product&#8217;\u0131m\u0131z\u0131 olu\u015ftural\u0131m.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nng g c product1\r\nng g c product2\r\nng g c product3\r\nng g c product4\r\nng g c product5\r\n<\/pre>\n<p>Bu product&#8217;lar &#8220;products&#8221; componenti alt\u0131nda y\u00f6nlendirileceklerinden dolay\u0131 route yap\u0131lanmas\u0131nda &#8220;products&#8221;a ait childs olarak eklenmeleri gerekmektedir.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n.\r\n.\r\n.\r\nexport const appRoutes: Route&#x5B;] = &#x5B;\r\n  { path: '', redirectTo: '\/home', pathMatch: 'full' },\r\n  { path: 'home', component: HomeComponent },\r\n  { path: 'about', component: AboutComponent },\r\n  { path: 'contact', component: ContactComponent },\r\n  {\r\n    path: 'products', component: ProductsComponent, children: &#x5B;\r\n      { path: &quot;product1&quot;, component: Product1Component },\r\n      { path: &quot;product2&quot;, component: Product2Component },\r\n      { path: &quot;product3&quot;, component: Product3Component },\r\n      { path: &quot;product4&quot;, component: Product4Component },\r\n      { path: &quot;product5&quot;, component: Product5Component }\r\n    ]\r\n  }\r\n];\r\n.\r\n.\r\n.\r\n<\/pre>\n<p>Bu i\u015flemden sonra &#8220;products.component.html&#8221; dosyas\u0131n\u0131n i\u00e7eri\u011fini a\u015fa\u011f\u0131daki gibi tasarlayal\u0131m.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n&lt;div class=&quot;row&quot;&gt;\r\n  &lt;div class=&quot;col-sx-4&quot;&gt;\r\n    &lt;ul class=&quot;list-group&quot;&gt;\r\n      &lt;li class=&quot;list-group-item&quot; routerLink=&quot;product1&quot;&gt;Product 1&lt;\/li&gt;\r\n      &lt;li class=&quot;list-group-item&quot; routerLink=&quot;product2&quot;&gt;Product 2&lt;\/li&gt;\r\n      &lt;li class=&quot;list-group-item&quot; routerLink=&quot;product3&quot;&gt;Product 3&lt;\/li&gt;\r\n      &lt;li class=&quot;list-group-item&quot; routerLink=&quot;product4&quot;&gt;Product 4&lt;\/li&gt;\r\n      &lt;li class=&quot;list-group-item&quot; routerLink=&quot;product5&quot;&gt;Product 5&lt;\/li&gt;\r\n    &lt;\/ul&gt;\r\n  &lt;\/div&gt;\r\n  &lt;div class=&quot;col-sx-8&quot;&gt;\r\n    &lt;router-outlet&gt;&lt;\/router-outlet&gt;\r\n  &lt;\/div&gt;\r\n&lt;\/div&gt;\r\n<\/pre>\n<p>Evet&#8230;<br \/>\nG\u00f6rd\u00fc\u011f\u00fcn\u00fcz \u00fczere bu \u015fekilde bir tasar\u0131 ger\u00e7ekle\u015ftirdi\u011fimizde de ba\u015far\u0131yla birden fazla router outlet kullanabilmekteyiz.<br \/>\n<a href=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2018\/10\/Angular-6-Multiple-Router-Outlet-Kullan\u0131m\u0131.gif\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2018\/10\/Angular-6-Multiple-Router-Outlet-Kullan\u0131m\u0131.gif\" alt=\"Angular 6 - Multiple Router Outlet Kullan\u0131m\u0131\" width=\"444\" height=\"408\" class=\"aligncenter size-full wp-image-9813\" \/><\/a><br \/>\nBurada dikkat etmeniz gereken husus, tercih etti\u011fimiz yakla\u015f\u0131mda child componentler y\u00f6nlendirilirken parent componentin adresinin yan\u0131na &#8220;parent-route\/child-route&#8221; olacak \u015fekilde adres olu\u015fturmaktad\u0131rlar.<\/p>\n<h3>Route Yap\u0131lanmas\u0131nda Outlet Tan\u0131mlama<\/h3>\n<p>Multiple Router Outlet yap\u0131s\u0131n\u0131 tasarlayabilmek i\u00e7in bir ba\u015fka yakla\u015f\u0131m\u0131m\u0131z ise route yap\u0131lanmas\u0131nda outlet tan\u0131mlamas\u0131d\u0131r. Uygulamada &#8220;name&#8221; \u00f6zelli\u011fi belirtilen router outlet&#8217;e, route yap\u0131lanmas\u0131nda &#8220;outlet&#8221; de\u011feriyle eri\u015fim sa\u011flanmakta ve bu \u015fekilde hangi componentin hangi route outlet alan\u0131nda yay\u0131nlanaca\u011f\u0131 belirtilmektedir.<\/p>\n<p>\u00d6rne\u011fimizde &#8220;products.component.html&#8221; dosyas\u0131ndaki router outlet&#8217;e a\u015fa\u011f\u0131daki gibi name \u00f6zelli\u011fi atayal\u0131m.<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;div class=&quot;row&quot;&gt;\r\n  &lt;div class=&quot;col-sx-4&quot;&gt;\r\n    &lt;ul class=&quot;list-group&quot;&gt;\r\n      &lt;li class=&quot;list-group-item&quot; routerLink=&quot;product1&quot;&gt;Product 1&lt;\/li&gt;\r\n      &lt;li class=&quot;list-group-item&quot; routerLink=&quot;product2&quot;&gt;Product 2&lt;\/li&gt;\r\n      &lt;li class=&quot;list-group-item&quot; routerLink=&quot;product3&quot;&gt;Product 3&lt;\/li&gt;\r\n      &lt;li class=&quot;list-group-item&quot; routerLink=&quot;product4&quot;&gt;Product 4&lt;\/li&gt;\r\n      &lt;li class=&quot;list-group-item&quot; routerLink=&quot;product5&quot;&gt;Product 5&lt;\/li&gt;\r\n    &lt;\/ul&gt;\r\n  &lt;\/div&gt;\r\n  &lt;div class=&quot;col-sx-8&quot;&gt;\r\n    &lt;router-outlet name=&quot;productOutlet&quot;&gt;&lt;\/router-outlet&gt;\r\n  &lt;\/div&gt;\r\n&lt;\/div&gt;\r\n<\/pre>\n<p>Ard\u0131ndan route \u015fablonumuzda a\u015fa\u011f\u0131daki gibi bu tan\u0131mlamaya uygun &#8220;outlet&#8221; de\u011ferlerini belirtelim.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n.\r\n.\r\n.\r\nexport const appRoutes: Route&#x5B;] = &#x5B;\r\n  { path: '', redirectTo: '\/home', pathMatch: 'full' },\r\n  { path: 'home', component: HomeComponent },\r\n  { path: 'about', component: AboutComponent },\r\n  { path: 'contact', component: ContactComponent },\r\n  {\r\n    path: 'products', component: ProductsComponent, children: &#x5B;\r\n      { path: &quot;product1&quot;, component: Product1Component, outlet: &quot;productOutlet&quot; },\r\n      { path: &quot;product2&quot;, component: Product2Component, outlet: &quot;productOutlet&quot; },\r\n      { path: &quot;product3&quot;, component: Product3Component, outlet: &quot;productOutlet&quot; },\r\n      { path: &quot;product4&quot;, component: Product4Component, outlet: &quot;productOutlet&quot; },\r\n      { path: &quot;product5&quot;, component: Product5Component, outlet: &quot;productOutlet&quot; }\r\n    ]\r\n  }\r\n];\r\n.\r\n.\r\n.\r\n<\/pre>\n<p>Bu \u015fekilde child componentlerden hangilerinin hangi route outlet&#8217;te yay\u0131nlanaca\u011f\u0131n\u0131 belirtmi\u015f oluyoruz.<\/p>\n<p>Bu i\u015flemden sonra &#8220;products.component.html&#8221; dosyas\u0131n\u0131 tekrardan a\u00e7\u0131p ilgili routerLink y\u00f6nlendirmelerini a\u015fa\u011f\u0131daki gibi d\u00fczenliyoruz.<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;div class=&quot;row&quot;&gt;\r\n  &lt;div class=&quot;col-sx-4&quot;&gt;\r\n    &lt;ul class=&quot;list-group&quot;&gt;\r\n      &lt;li class=&quot;list-group-item&quot; &#x5B;routerLink]=&quot;&#x5B;{outlets:{productOutlet:&#x5B;'product1']}}]&quot;&gt;Product 1&lt;\/li&gt;\r\n      &lt;li class=&quot;list-group-item&quot; &#x5B;routerLink]=&quot;&#x5B;{outlets:{productOutlet:&#x5B;'product2']}}]&quot;&gt;Product 2&lt;\/li&gt;\r\n      &lt;li class=&quot;list-group-item&quot; &#x5B;routerLink]=&quot;&#x5B;{outlets:{productOutlet:&#x5B;'product3']}}]&quot;&gt;Product 3&lt;\/li&gt;\r\n      &lt;li class=&quot;list-group-item&quot; &#x5B;routerLink]=&quot;&#x5B;{outlets:{productOutlet:&#x5B;'product4']}}]&quot;&gt;Product 4&lt;\/li&gt;\r\n      &lt;li class=&quot;list-group-item&quot; &#x5B;routerLink]=&quot;&#x5B;{outlets:{productOutlet:&#x5B;'product5']}}]&quot;&gt;Product 5&lt;\/li&gt;\r\n    &lt;\/ul&gt;\r\n  &lt;\/div&gt;\r\n  &lt;div class=&quot;col-sx-8&quot;&gt;\r\n    &lt;router-outlet name=&quot;productOutlet&quot;&gt;&lt;\/router-outlet&gt;\r\n  &lt;\/div&gt;\r\n&lt;\/div&gt;\r\n<\/pre>\n<p>Burada kullan\u0131lan &#8220;[{outlets:{productOutlet:[&#8216;product1&#8217;]}}]&#8221; de\u011ferini izah edersek e\u011fer; &#8220;outlets&#8221; tan\u0131mlamas\u0131yla uygulamada birazdan ad\u0131n\u0131 belirtece\u011fimiz herhangi bir outlet \u00fczerinde \u00e7al\u0131\u015facak bir adres oldu\u011funu belirtmekteyiz. Devam\u0131nda bu outlet&#8217;in &#8220;productOutlet&#8221; de\u011feri ile e\u015fde\u011fer olaca\u011f\u0131n\u0131 belirtiyoruz ve &#8220;[&#8216;product1&#8217;]&#8221; alan\u0131 ilede \u00e7al\u0131\u015ft\u0131raca\u011f\u0131 child component&#8217;in &#8220;path&#8221; de\u011ferini belirtiyoruz.<\/p>\n<p>Uygulamay\u0131 bu \u015fekilde yap\u0131land\u0131rd\u0131ktan sonra;<br \/>\n<a href=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2018\/10\/Angular-6-Multiple-Router-Outlet-Kullan\u0131m\u0131-1.gif\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2018\/10\/Angular-6-Multiple-Router-Outlet-Kullan\u0131m\u0131-1.gif\" alt=\"Angular 6 - Multiple Router Outlet Kullan\u0131m\u0131\" width=\"564\" height=\"404\" class=\"aligncenter size-full wp-image-9820\" \/><\/a><br \/>\n\u015feklinde \u00e7al\u0131\u015ft\u0131\u011f\u0131n\u0131 g\u00f6rmekteyiz. <\/p>\n<p>Bu ikinci kullan\u0131m, daha kompleks ve ayn\u0131 component i\u00e7erisinde ikiden fazla route outlet yap\u0131lanmas\u0131 s\u00f6z konusu oldu\u011fu durumlarda tercih edilebilir bir mahiyettedir.<\/p>\n<p>\u0130lgilenenlerin faydalanmas\u0131 dile\u011fiyle&#8230;<\/p>\n<p>Sonraki yaz\u0131lar\u0131mda g\u00f6r\u00fc\u015fmek \u00fczere&#8230;<br \/>\n\u0130yi \u00e7al\u0131\u015fmalar dilerim&#8230;<\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>Merhaba, Single Page Application \u015feklinde nitelendirdi\u011fimiz web tabanl\u0131 uygulamalar geli\u015ftirmemizi sa\u011flayan Angular mimarisi, sayfa taleplerine cevap olarak component yap\u0131lar\u0131 ile kar\u015f\u0131l\u0131k verdi\u011finden dolay\u0131 uygulaman\u0131n bel kemi\u011fi tek bir router outlet&#8217;a ba\u011flanmakta ve son kullanc\u0131yla&#46;&#46;&#46;<!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":1,"featured_media":9823,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2420,2599],"tags":[2156,2600,2685],"class_list":["post-9797","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-angular","category-angular-6","tag-angular","tag-angular-6","tag-multiple-router-outlet"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/9797","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/comments?post=9797"}],"version-history":[{"count":23,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/9797\/revisions"}],"predecessor-version":[{"id":9824,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/9797\/revisions\/9824"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/media\/9823"}],"wp:attachment":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/media?parent=9797"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/categories?post=9797"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/tags?post=9797"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}