scoop position nested routes

This commit is contained in:
Alexandre Chopin 2016-12-11 16:40:18 +01:00
parent ce0a89508e
commit d09fdfb78e
4 changed files with 20 additions and 12 deletions

View File

@ -1,5 +0,0 @@
<template>
<div>
Comments list
</div>
</template>

View File

@ -0,0 +1,5 @@
<template>
<div class="container">
Comments only
</div>
</template>

View File

@ -1,9 +1,10 @@
<template> <template>
<div class="user"> <div class="container">
<h2>User</h2>
<h3>{{ name }}</h3> <h3>{{ name }}</h3>
<h4>@{{ username }}</h4> <h4>@{{ username }}</h4>
<p>Email : {{ email }}</p> <p>Email : {{ email }}</p>
<p><router-link to="/">List of users</router-link></p> <p><router-link to="/users">List of users</router-link></p>
</div> </div>
</template> </template>
@ -22,9 +23,14 @@ export default {
</script> </script>
<style scoped> <style scoped>
.user { .container
{
text-align: center;
overflow: hidden;
}
/*.user {
text-align: center; text-align: center;
margin-top: 100px; margin-top: 100px;
font-family: sans-serif; font-family: sans-serif;
} }*/
</style> </style>

View File

@ -16,7 +16,6 @@ function recursiveRoutes(routes, tab) {
res += tab + '\tcomponent: ' + route._name res += tab + '\tcomponent: ' + route._name
res += (route.name) ? ',\n\t' + tab + 'name: ' + JSON.stringify(route.name) : '' res += (route.name) ? ',\n\t' + tab + 'name: ' + JSON.stringify(route.name) : ''
res += (route.alias) ? ',\n\t' + tab + 'alias: ' + JSON.stringify(route.alias) : '' res += (route.alias) ? ',\n\t' + tab + 'alias: ' + JSON.stringify(route.alias) : ''
res += (route.redirect) ? ',\n\t' + tab + 'redirect: ' + JSON.stringify(route.redirect) : ''
res += (route.meta) ? ',\n\t' + tab + 'meta: ' + JSON.stringify(route.meta) : '' res += (route.meta) ? ',\n\t' + tab + 'meta: ' + JSON.stringify(route.meta) : ''
res += (route.children) ? ',\n\t' + tab + 'children: [\n' + recursiveRoutes(routes[i].children, tab + '\t\t') + '\n\t' + tab + ']' : '' res += (route.children) ? ',\n\t' + tab + 'children: [\n' + recursiveRoutes(routes[i].children, tab + '\t\t') + '\n\t' + tab + ']' : ''
res += '\n' + tab + '}' + (i + 1 === routes.length ? '' : ',\n') res += '\n' + tab + '}' + (i + 1 === routes.length ? '' : ',\n')
@ -33,8 +32,11 @@ const scrollBehavior = (to, from, savedPosition) => {
// savedPosition is only available for popstate navigations. // savedPosition is only available for popstate navigations.
return savedPosition return savedPosition
} else { } else {
// Scroll to the top by default let position = {}
let position = { x: 0, y: 0 } // if no children detected
if (to.matched.length < 2) {
position = { x: 0, y: 0 }
}
// if link has anchor, scroll to anchor by returning the selector // if link has anchor, scroll to anchor by returning the selector
if (to.hash) { if (to.hash) {
position = { selector: to.hash } position = { selector: to.hash }