vue+admin:根据路由动态修改浏览器标签页上的title 在utils⽂件夹下新建⼯具函数get-page-title.ts-》在permission.ts的全局路由中设置document.title =
a.title)即可。(注:setting.ts⽂件中可设置默认值。)
// setting.ts
interface ISettings {
title: string // Overrides the default title
showSettings: boolean // Controls settings panel display
showTagsView: boolean // Controls tagsview display
vue element adminshowSidebarLogo: boolean // Controls siderbar logo display
fixedHeader: boolean // If true, will fix the header component
errorLog: string[] // The env to enable the errorlog component, default 'production' only
sidebarTextTheme: boolean // If true, will change active text color for sidebar based on theme
devServerPort: number // Port number for webpack-dev-server
mockServerPort: number // Port number for mock server
}
// You can customize below settings :)
const settings: ISettings = {
title: 'XXX系统',
showSettings: false,
showTagsView: true,
fixedHeader: false,
showSidebarLogo: true,
errorLog: ['production'],
sidebarTextTheme: true,
devServerPort: 9527,
mockServerPort: 9528
}
export default settings
// utils/get-page-title.ts
import defaultSettings from '@/settings'
const title = defaultSettings.title || 'Vue Element Admin'
export default function getPageTitle(pageTitle: string) {
if (pageTitle) {
return `${pageTitle} - ${title}`
}
return `${title}`
}
// permission.ts
...
const whiteList = ['/login', '/auth-redirect']
import getPageTitle from '@/utils/get-page-title'
router.beforeEach(async(to: Route, _: Route, next: any) => {
NProgress.start()
document.title = a.title) // 根据路由动态修改标题名称。
if (ken) {
if (to.path === '/login') {
next({ path: '/' })
NProgress.done()
} else {
if (les.length === 0) {
// ⽣成路由菜单
// if (uRoutes.length === 0) {
// await MenuModule.GetMenuRoutes()
// console.log('uRoutes', uRoutes)
// }
try {
/
/ ⽤户信息
await UserModule.GetUserInfo()
const roles = les
PermissionModule.GenerateRoutes(roles)
utes = [...uRoutes, ...utes] router.addRoutes([...uRoutes, ...utes])
console.log('utes', utes)
next({ ...to, replace: true })
} catch (err) {
UserModule.ResetToken()
<(err || 'Has Error')
next(`/login?redirect=${to.path}`)
NProgress.done()
}
} else {
console.log('next', to)
next()
}
}
} else {
// Has no token
if (whiteList.indexOf(to.path) !== -1) {
// In the free login whitelist, go directly
next()
} else {
// Other pages that do not have permission to access are redirected to the login page. next(`/login?redirect=${to.path}`)
NProgress.done()
}
}
})
router.afterEach((to: Route) => {
NProgress.done()
document.title = a.title)
})
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论