Skip to content

Commit

Permalink
feat: 完成 vue-router 路由划分以及模块配置 #61
Browse files Browse the repository at this point in the history
  • Loading branch information
haitaodesign committed Aug 20, 2019
1 parent c331fdc commit 48acb1f
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/App.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<template>
<div id="app">
Vue Cli 3
<router-view></router-view>
</div>
</template>

<script>
export default {
name: 'app'
name: 'App'
}
</script>

Expand Down
7 changes: 7 additions & 0 deletions src/router/home/home.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default [
{
path: '/home',
home: 'home',
component: () => import(/* webpackChunkName: "home" */ '@/views/home/index.vue')
}
]
File renamed without changes.
7 changes: 7 additions & 0 deletions src/router/home/other.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default [
{
path: '/other',
name: 'other',
component: () => import(/* webpackChunkName: "other" */ '@/views/other/index.vue')
}
]
10 changes: 10 additions & 0 deletions src/router/login/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

const modules = require.context('.', true, /\.js$/)
let moduleRoutes = []
modules.keys().forEach(key => {
if (key !== './index.js') {
moduleRoutes = moduleRoutes.concat(modules(key).default)
}
})
// console.log(moduleRoutes)
export default moduleRoutes
6 changes: 6 additions & 0 deletions src/router/login/login.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default [
{
path: '/login',
component: () => import(/* webpackChunkName: "login" */ '@/views/login/index.vue')
}
]
3 changes: 0 additions & 3 deletions src/router/modules/compontents.js

This file was deleted.

12 changes: 9 additions & 3 deletions src/router/routes.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import RouterModules from './modules'
import HomeRouters from './home'
import LoginRouters from './login'
const commonRoute = [{
path: '/'
path: '/',
name: 'root',
redirect: '/home',
component: () => import(/* webpackChunkName: "layout" */ '@/views/layout/index.vue'),
children: HomeRouters
}]
export default commonRoute.concat(RouterModules)
// TODO: 模块多到一定的规模,可以通过按需构建达到加快开发环境体验的目的
export default commonRoute.concat(LoginRouters)
11 changes: 11 additions & 0 deletions src/views/home/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<template>
<div class="home">
dddd
</div>
</template>

<script>
export default {
name: 'Home'
}
</script>
14 changes: 14 additions & 0 deletions src/views/layout/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<template>
<div class="layout">
<router-link :to="{ name: 'other' }">
<span>other</span>
</router-link>
<router-view></router-view>
</div>
</template>

<script>
export default {
name: 'Layout'
}
</script>
11 changes: 11 additions & 0 deletions src/views/login/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<template>
<div class="login">
login
</div>
</template>

<script>
export default {
name: 'Login'
}
</script>
11 changes: 11 additions & 0 deletions src/views/other/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<template>
<div class="ohter">
other
</div>
</template>

<script>
export default {
name: 'Ohter'
}
</script>

0 comments on commit 48acb1f

Please sign in to comment.