I have seen in several different places the following type of route definition:
{ path : '/dashboard',
component: { render (c) { return c('router-view') }},
children:[{
path:"",
component: Dashboard
}]
},
I am trying to understand how this is different then
{ path : '/dashboard',
component: Dashboard
},
I think it is related to the optional addition of child routs (e.g. /dashboard/user) so that and the children array here just explains that the Dashboard component renders the path /dashboard whereas if I had the second piece of code then it can only render /dashboard.
What I do want to know is what exactly this does
component: { render (c) { return c('router-view') }},
I assume this is some form of a degenerated component but I don't understand what exactly does it do and how.
I don't know the rest of your code, but it looks like this might be an implementation of the vue-router Lazy Loading functionality. Basically, Vue + Webpack are going to split your code into chunks and only load those chunks whenever the user attempts to navigate to those routes, rather than loading them all and creating a bigger bundle to download than necessary.
In Vue, a component is created using an object containing its configuration.
The simplest possible component may look something like this
In some cases, a developer might not want to use
template
, and would want to create element from scratch using pure Javascript. That's where render function comes in.To change the example above to using render function:
They would produce the exact same result:
In other words,
render function
is simply an alternative to usingtemplate
.is equal to
is equal to
Because render function is
closer-to-the-compiler
, it's faster compared to using template. That's probably why the author of your code does it this way.