{"id":698,"date":"2019-08-08T09:36:45","date_gmt":"2019-08-08T13:36:45","guid":{"rendered":"http:\/\/salzlechner.com\/dev\/?p=698"},"modified":"2020-10-10T09:33:20","modified_gmt":"2020-10-10T13:33:20","slug":"using-vue-router-part-4-named-views","status":"publish","type":"post","link":"http:\/\/salzlechner.com\/dev\/2019\/08\/08\/using-vue-router-part-4-named-views\/","title":{"rendered":"Using Vue Router Part 4 &#8211; Named Views"},"content":{"rendered":"\n[et_pb_section][et_pb_row][et_pb_column type=&#8221;4_4&#8243;][et_pb_text]to show multiple different views on the same route, Vue router supports &#8216;named views&#8217;.\n\nnamed views allow us to create multiple named router views and then assign components to all views in the route.\n\nto show this we modify our main router view in App.vue as follows\n<pre class=\"lang:default decode:true \">&lt;template&gt;\n  &lt;div id=\"app\"&gt;\n    &lt;img src=\".\/assets\/logo.png\"&gt;\n\n\n    &lt;router-link to=\"\/\"&gt;\/Home&lt;\/router-link&gt;  \n    &lt;router-link to=\"\/users\"&gt;\/users&lt;\/router-link&gt;  \n    &lt;router-link to=\"\/customers\"&gt;\/customers&lt;\/router-link&gt;  \n\n    &lt;p&gt;Main Router View&lt;\/p&gt;\n\n    &lt;router-view\/&gt;\n\n    &lt;p&gt;Secondary Router View&lt;\/p&gt;\n\n    &lt;router-view name=\"secondary\"\/&gt;\n  &lt;\/div&gt;\n&lt;\/template&gt;<\/pre>\nin addition to our main router view we added a secondary router view that is aptly named secondary\n\nnow we also create a new component called CustomersSecondary.vue with the following content\n<pre class=\"lang:default decode:true\">&lt;template&gt;\n    &lt;div&gt;\n        &lt;div&gt;CUSTOMERS SECONDARY&lt;\/div&gt;\n\n    &lt;\/div&gt;\n&lt;\/template&gt;\n\n&lt;script&gt;\nexport default {\n    \n}\n&lt;\/script&gt;<\/pre>\nand then we modify our customers route as follows\n<pre class=\"lang:default decode:true \">    {\n      path: '\/customers',\n      name: 'customers',\n      components: \n      {\n        default: Customers,\n        secondary: CustomersSecondary\n      }\n    },<\/pre>\ninstead of pointing the route to a single component we use the components attribute of the route to assign multiple components. The default component will be shown in the default router view and the component assigned to &#8216;secondary&#8217; the name of our router view will be shown in the named router view\n\n\n\t\t<div class='author-shortcodes'>\n\t\t\t<div class='author-inner'>\n\t\t\t\t<div class='author-image'>\n\t\t\t<img src='http:\/\/salzlechner.com\/dev\/wp-content\/uploads\/sites\/2\/2016\/02\/mike5crop-566174_60x60.jpg' alt='' \/>\n\t\t\t<div class='author-overlay'><\/div>\n\t\t<\/div> \n\t\t<div class='author-info'>\n\t\t\tMichael Salzlechner is the CEO of StarZen Technologies, Inc.\n\nHe was part of the Windows Team at Data Access Worldwide that created the DataFlex for Windows Product before joining&nbsp;<a href=\"http:\/\/starzen.com\">StarZen Technologies<\/a>. StarZen Technologies provides consulting services as well as custom Application development and third party products\n\t\t<\/div>\n\t\t\t<\/div>\n\t\t<\/div>\n\n&nbsp;[\/et_pb_text][\/et_pb_column][\/et_pb_row][\/et_pb_section]\n","protected":false},"excerpt":{"rendered":"<p><div class=\"et_pb_section et_pb_section_0 et_section_regular\" >\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t<\/div><div class=\"et_pb_row et_pb_row_0 et_pb_row_empty\">\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t<\/div><div class=\"et_pb_module et_pb_text et_pb_text_0  et_pb_text_align_left et_pb_bg_layout_light\">\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t<\/div>to show multiple different views on the same route, Vue router supports &#8216;named views&#8217;. named views allow us to create multiple named router views and then assign components to all views in the route. to show this we modify our main router view in App.vue as follows &lt;template&gt; &lt;div id=&#8221;app&#8221;&gt; &lt;img src=&#8221;.\/assets\/logo.png&#8221;&gt; &lt;router-link to=&#8221;\/&#8221;&gt;\/Home&lt;\/router-link&gt; &lt;router-link [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":722,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"on","_et_pb_old_content":"to show multiple different views on the same route, Vue router supports 'named views'.\n\nnamed views allow us to create multiple named router views and then assign components to all views in the route.\n\nto show this we modify our main router view in App.vue as follows\n<pre class=\"lang:default decode:true crayon-selected\">&lt;template&gt;\n  &lt;div id=\"app\"&gt;\n    &lt;img src=\".\/assets\/logo.png\"&gt;\n\n\n    &lt;router-link to=\"\/\"&gt;\/Home&lt;\/router-link&gt;  \n    &lt;router-link to=\"\/users\"&gt;\/users&lt;\/router-link&gt;  \n    &lt;router-link to=\"\/customers\"&gt;\/customers&lt;\/router-link&gt;  \n\n    &lt;p&gt;Main Router View&lt;\/p&gt;\n\n    &lt;router-view\/&gt;\n\n    &lt;p&gt;Secondary Router View&lt;\/p&gt;\n\n    &lt;router-view name=\"secondary\"\/&gt;\n  &lt;\/div&gt;\n&lt;\/template&gt;<\/pre>\nin addition to our main router view we added a secondary router view that is aptly named secondary\n\nnow we also create a new component called CustomersSecondary.vue with the following content\n<pre class=\"lang:default decode:true\">&lt;template&gt;\n    &lt;div&gt;\n        &lt;div&gt;CUSTOMERS SECONDARY&lt;\/div&gt;\n\n    &lt;\/div&gt;\n&lt;\/template&gt;\n\n&lt;script&gt;\nexport default {\n    \n}\n&lt;\/script&gt;<\/pre>\nand then we modify our customers route as follows\n<pre class=\"lang:default decode:true \">    {\n      path: '\/customers',\n      name: 'customers',\n      components: \n      {\n        default: Customers,\n        secondary: CustomersSecondary\n      }\n    },<\/pre>\ninstead of pointing the route to a single component we use the components attribute of the route to assign multiple components. The default component will be shown in the default router view and the component assigned to 'secondary' the name of our router view will be shown in the named router view\n\n[author] [author_image timthumb='on']http:\/\/salzlechner.com\/dev\/wp-content\/uploads\/sites\/2\/2016\/02\/mike5crop.jpg[\/author_image] [author_info]Michael Salzlechner is the CEO of StarZen Technologies, Inc.\n\nHe was part of the Windows Team at Data Access Worldwide that created the DataFlex for Windows Product before joining&nbsp;<a href=\"http:\/\/starzen.com\">StarZen Technologies<\/a>. StarZen Technologies provides consulting services as well as custom Application development and third party products\n\n[\/author_info] [\/author]\n\n&nbsp;","_et_gb_content_width":"","ngg_post_thumbnail":0,"footnotes":""},"categories":[38],"tags":[],"class_list":["post-698","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-vue-js"],"_links":{"self":[{"href":"http:\/\/salzlechner.com\/dev\/wp-json\/wp\/v2\/posts\/698","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/salzlechner.com\/dev\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/salzlechner.com\/dev\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/salzlechner.com\/dev\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/salzlechner.com\/dev\/wp-json\/wp\/v2\/comments?post=698"}],"version-history":[{"count":5,"href":"http:\/\/salzlechner.com\/dev\/wp-json\/wp\/v2\/posts\/698\/revisions"}],"predecessor-version":[{"id":780,"href":"http:\/\/salzlechner.com\/dev\/wp-json\/wp\/v2\/posts\/698\/revisions\/780"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/salzlechner.com\/dev\/wp-json\/wp\/v2\/media\/722"}],"wp:attachment":[{"href":"http:\/\/salzlechner.com\/dev\/wp-json\/wp\/v2\/media?parent=698"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/salzlechner.com\/dev\/wp-json\/wp\/v2\/categories?post=698"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/salzlechner.com\/dev\/wp-json\/wp\/v2\/tags?post=698"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}