fix(router of debugComponents)

This commit is contained in:
songwanli2025@163.com 2020-03-20 17:32:05 +08:00
parent 178c421965
commit 549aea2b2c
5 changed files with 37 additions and 33 deletions

View File

@ -1,12 +1,14 @@
import { Vue, router, i18n } from './init'
import { Vue, i18n } from './init'
import hljs from './hljs'
import demoRouterView from './demoRouterView'
import NaiveUI from '../lib/index'
import '../lib/styles/index.css'
import createRouter from './routes/router'
import { routes } from './routes/routes'
Vue.use(NaiveUI)
NaiveUI.setHljs(hljs)
const router = createRouter(Vue, routes)
new Vue({
...demoRouterView,
router,

View File

@ -1,13 +1,17 @@
import { Vue, router, routes, childRoutes, i18n } from './init'
import { Vue, i18n } from './init'
import debugRouteMixin from './routes/debugRouteMixin'
import hljs from './hljs'
import demoRouterView from './demoRouterView'
import NaiveUI from '../src/index'
import '../styles/index.scss'
import { routes, childRoutes } from './routes/routes'
import createRouter from './routes/router'
debugRouteMixin(routes, childRoutes)
const router = createRouter(Vue, routes)
Vue.use(NaiveUI)
NaiveUI.setHljs(hljs)

View File

@ -1,5 +1,4 @@
import Vue from 'vue'
import VueRouter from 'vue-router'
import VueI18n from 'vue-i18n'
import ComponentDemo from './utils/ComponentDemo'
import ComponentDemos from './utils/ComponentDemos'
@ -7,10 +6,8 @@ import ComponentDocumentation from './utils/ComponentDocumentation'
import DocumentationWrapper from './utils/DocumentationWrapper'
import EditOnGithubButton from './utils/EditOnGithubButton'
import EditOnGithubHeader from './utils/EditOnGithubHeader'
import { routes, childRoutes } from './routes/routes'
import './styles/demo.scss'
Vue.use(VueRouter)
Vue.use(VueI18n)
const i18n = new VueI18n({
@ -24,23 +21,4 @@ Vue.component('ComponentDocumentation', ComponentDocumentation)
Vue.component('EditOnGithubButton', EditOnGithubButton)
Vue.component('EditOnGithubHeader', EditOnGithubHeader)
const router = new VueRouter({
mode: 'history',
routes
})
router.beforeEach(function (to, from, next) {
Vue.prototype.$NLoadingBar.theme = to.params.theme
if (to.path !== from.path) {
Vue.prototype.$NLoadingBar.start()
}
next()
})
router.afterEach(function (to, from) {
if (to.path !== from.path) {
Vue.prototype.$NLoadingBar.finish()
}
})
export { Vue, router, routes, childRoutes, i18n }
export { Vue, i18n }

View File

@ -13,7 +13,7 @@ import scrollbarDebug2 from '../debugComponents/scrollbarDebug2'
import { withPrefix } from './utils'
const rootDebugRoutes = [
const childDebugRoutes = [
{
path: '/n-popover-debug',
component: popoverDebug
@ -25,10 +25,7 @@ const rootDebugRoutes = [
{
path: '/n-cascader-debug',
component: cascaderDebug
}
]
const childDebugRoutes = [
},
{ path: '/n-scrollbar-debug2', component: scrollbarDebug2 },
{ path: '/n-date-picker-debug', component: datePickerDebug },
{ path: '/n--debug', component: suffixDebug },
@ -41,6 +38,6 @@ const childDebugRoutes = [
]
export default function debugRouteMixin (routes, childRoutes) {
routes.unshift(rootDebugRoutes)
childRoutes.unshift(withPrefix('/:lang/:theme/doc', childDebugRoutes))
childRoutes.unshift(...withPrefix('/:lang/:theme/doc', childDebugRoutes))
routes[0].children[1].children = childRoutes
}

23
demo/routes/router.js Normal file
View File

@ -0,0 +1,23 @@
import VueRouter from 'vue-router'
export default function createRouter (Vue, routes) {
Vue.use(VueRouter)
const router = new VueRouter({
mode: 'history',
routes
})
router.beforeEach(function (to, from, next) {
Vue.prototype.$NLoadingBar.theme = to.params.theme
if (to.path !== from.path) {
Vue.prototype.$NLoadingBar.start()
}
next()
})
router.afterEach(function (to, from) {
if (to.path !== from.path) {
Vue.prototype.$NLoadingBar.finish()
}
})
return router
}