Skip to content

Commit

Permalink
refactor(router): organization and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuagraber committed Mar 15, 2024
1 parent 6060eae commit 0232de3
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions client/src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,22 @@ const META_PROPERTIES = [...DEFAULT_META_TAGS.keys(), 'og:url'];
* @param {RouteLocationNormalized} to Vue router route location
*/
function refreshMetaTagsByRoute(to) {
// Get nearest matched route that has title / meta tag overrides
const nearestRouteWithTitle = [...to.matched]
.reverse()
.find((r) => r.meta && r.meta.title);
.find((route) => route?.meta?.title);

const nearestRouteWithMeta = [...to.matched]
.reverse()
.find((r) => r.meta && r.meta.metaTags);
.find((route) => route?.meta?.metaTags);

// Update document title
document.title =
nearestRouteWithTitle?.meta?.title ?? DEFAULT_META_TAGS.get('title');
Array.from(document.querySelectorAll('[data-controlled-meta]')).map((el) =>
el.parentNode.removeChild(el),

// Update meta tags
Array.from(document.querySelectorAll('[data-controlled-meta]')).forEach(
(el) => el.parentNode.removeChild(el),
);

META_PROPERTIES.filter((prop) => prop !== 'title')
Expand Down

0 comments on commit 0232de3

Please sign in to comment.