3

I want to load 3 Components at a time like that:

<app-header />
<app-main />
<app-footer />

But I want to load Router View also in this page.

<app-header />
<router-view />
<app-footer />

While I will click on the router-link then <app-main /> will be vanish and <router-view /> will be visible.

Is there any better way to handle it without if or show?

2 Answers 2

1

You can pass router-view via slot to your app-main component like this:

<app-header />
<app-main>
  <router-view/>
</app-main>
<app-footer />

Also you need to insert a slot tag in your app-main component like this:

<template>
  <!-- your code -->
    <slot></slot>
  <!-- ... -->
</template>

For more details visit https://v2.vuejs.org/v2/guide/components-slots.html

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks but I need to replace app-main with router-view.
0

You can remove <app-main /> from the template replace it with <router-view/>, now whenever you need app-main component or some other component in place configure it using routes definition.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.