@rrc-materials/core
Version:
rrc materials for core
36 lines (31 loc) • 1.19 kB
JavaScript
import { isFunction } from '@rrc/utils'
import NProgress from 'nprogress'
export default function RouterConfig (router, store, options) {
router.beforeEach((to, form, next) => {
const { name, matched, fullPath } = to
NProgress.start()
if (matched.some(record => record.meta.isAddTab)) {
const meta = to.meta
const title = meta.title
// tab(标签名字)
let label = title
// tab name (标签Id)
// rc-cache 销毁 key 的问题 此处不适用name 改用 fullPath
const tabName = name === 'home' ? 'home' : options.removeTabHash ? fullPath.replace(/#(.*)$/, '') : fullPath
// 如果标签 名字是用function 返回的 则认为他是需要打开多个同一个标签 则使用连接 作为标签name
if (isFunction(title)) {
label = title(to)
}
store.commit('rcMaterialsTabsAddTab', { name: tabName, fullPath, label: label || '新标签', meta })
}
next()
})
router.afterEach((to) => {
const { name } = to
if (options.noAfterRouteIsLoading.indexOf(name) === -1) {
setTimeout(() => {
NProgress.done()
}, 10)
}
})
}