This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div> | |
<h1>This is an users page</h1> | |
<router-view /> | |
</div> | |
</template> | |
<script> | |
export default { | |
name: 'Users' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default pages | |
// Note: remove nested routes from pages | |
.filter(path => !path.some(childrenFilter)) | |
.map(async path => { | |
const { default: component } = await import(`../views/${path.join('/')}`) | |
const { name } = component | |
const route = `/${generateRoute([...path])}` | |
let children = [] | |
if (childrenByPath[route]) { | |
const promises = childrenByPath[route].map(async ({ path, route }) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const childrenFilter = p => ~p.indexOf('^') | |
const childrenByPath = pages | |
// Note: filter pages by children routes | |
.filter(path => path.some(childrenFilter)) | |
.map(path => { | |
// Note: copy path and remove special char ^ | |
const copy = [...path] | |
copy[copy.length - 1] = copy[copy.length - 1].slice(1) | |
// Note: generate key to identify parent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const generateRoute = path => { | |
// Note: remove first element if route starts with index | |
if (path[0].toLowerCase().startsWith('index') && path.length > 1) { | |
path.shift() | |
} | |
// Note: handle root routes | |
if (path.length === 1) { | |
const shortcut = path[0].toLowerCase() | |
return shortcut.startsWith('index') | |
? '' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div> | |
<h1>This is a page to edit the post with id {{ $route.params.id }}</h1> | |
</div> | |
</template> | |
<script> | |
export default { | |
name: "PostEdit" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div> | |
<h1>This is a page of the post with id {{ $route.params.id }}</h1> | |
</div> | |
</template> | |
<script> | |
export default { | |
name: "PostDetails" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div> | |
<h1>This is a post creation page</h1> | |
</div> | |
</template> | |
<script> | |
export default { | |
name: "PostCreate" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div> | |
<h1>This is a list of posts page</h1> | |
</div> | |
</template> | |
<script> | |
export default { | |
name: "Posts" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const generateRoute = path => { | |
// Note: remove first element if route starts with index | |
if (path[0].toLowerCase().startsWith('index') && path.length > 1) { | |
path.shift() | |
} | |
// Note: handle root routes | |
if (path.length === 1) { | |
const shortcut = path[0].toLowerCase() | |
return shortcut.startsWith('index') | |
? '' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createApp } from 'vue' | |
import App from './App.vue' | |
const init = async() => { | |
const module = await import('./router'); | |
const router = await module.default; | |
createApp(App).use(router).mount('#app') | |
} | |
init() |