admin管理员组文章数量:1417710
Hi guys I have the following route which I try to call different ponents that should load simultaneously using Nested Routes, I have a Navigational Bar (called NavBar) to be loaded together with my Main Form (called MainForm). Somehow the MainForm isn't called, only the NavBar. I also have a form with the absence of a NavBar hence the next route entry. The router contains the following code:
import MainForm from '@/ponents/MainForm';
import NavBar from '@/ponents/NavBar';
Vue.use(Router);
export default new Router({
routes: [
{
path: '',
name: 'NavBar',
ponent: NavBar,
children: [
{
path: '/form/:id',
ponent: MainForm
}
]
},
{
path: '/formNoNavBar/:id',
ponent: MainForm
}
]
});
On the first entry what happens is that the NavBar gets loaded by the app when I go to http://localhost:8080/#/form/sampleid but it doesn't load the MainForm. On the second entry, there are no problems loading the MainForm. What also further my doubts is that I added this to my MainForm.vue:
export default {
name: 'MainForm',
created: function () {
console.log('heya');
} ....
On the second route entry, "heya" displays on the console but on the first it doesn't. How do I fix the nested route I created to load both the NavBar and the MainForm vue files?
Hi guys I have the following route which I try to call different ponents that should load simultaneously using Nested Routes, I have a Navigational Bar (called NavBar) to be loaded together with my Main Form (called MainForm). Somehow the MainForm isn't called, only the NavBar. I also have a form with the absence of a NavBar hence the next route entry. The router contains the following code:
import MainForm from '@/ponents/MainForm';
import NavBar from '@/ponents/NavBar';
Vue.use(Router);
export default new Router({
routes: [
{
path: '',
name: 'NavBar',
ponent: NavBar,
children: [
{
path: '/form/:id',
ponent: MainForm
}
]
},
{
path: '/formNoNavBar/:id',
ponent: MainForm
}
]
});
On the first entry what happens is that the NavBar gets loaded by the app when I go to http://localhost:8080/#/form/sampleid but it doesn't load the MainForm. On the second entry, there are no problems loading the MainForm. What also further my doubts is that I added this to my MainForm.vue:
export default {
name: 'MainForm',
created: function () {
console.log('heya');
} ....
On the second route entry, "heya" displays on the console but on the first it doesn't. How do I fix the nested route I created to load both the NavBar and the MainForm vue files?
Share Improve this question asked May 23, 2018 at 3:18 The BassmanThe Bassman 2,3615 gold badges30 silver badges41 bronze badges1 Answer
Reset to default 7I think you misunderstood how Vue nested route works. You think that a child route ponent can load an entirely different ponent from its parent route, right?
The parent route ponent should be a layout that enpasses the child route ponent. The parent route ponent should have <router-view></router-view>
inside. <router-view></router-view>
will be replaced by the child route ponent.
This is a pretty good example => https://codesandbox.io/s/qq8zk1n36. See Layout.vue
本文标签: javascriptVueRouter Child Component is not calledStack Overflow
版权声明:本文标题:javascript - VueRouter: Child Component is not called - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745275325a2651150.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论