Skip to content

Commit

Permalink
Added dynamic title based on route
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardoboss committed Aug 11, 2022
1 parent d8ce12c commit dd25950
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
VUE_APP_API_BASE=https://localhost:7262/api/
VUE_APP_PRIMARY_COLOR='#8af'
VUE_APP_PRIMARY_FOREGROUND_COLOR='#000'
VUE_APP_PRIMARY_FOREGROUND_COLOR='#000'
VUE_APP_NAME='My Wiki'
16 changes: 14 additions & 2 deletions src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,26 @@ const routes: Array<RouteRecordRaw> = [
path: '/:path(.*)*',
component: NotFoundView,
meta: {
title: '',
title: 'Not Found',
}
}
]

const router = createRouter({
history: createWebHistory(process.env.BASE_URL),
routes
routes,
})

router.beforeEach((to, from, next) => {
if (to.meta.title) {
document.title = to.meta.title + ' \u2022 ' + process.env.VUE_APP_NAME;
} else if (to.params.location) {
document.title = (to.params.location as string).split('/').pop() + ' \u2022 ' + process.env.VUE_APP_NAME;
} else {
document.title = process.env.VUE_APP_NAME;
}

next()
});

export default router

0 comments on commit dd25950

Please sign in to comment.