Skip to content

Instantly share code, notes, and snippets.

@reinink
Created March 9, 2019 17:02
Show Gist options
  • Save reinink/2488a5ff6c314eddba50b0a6932c72d9 to your computer and use it in GitHub Desktop.
Save reinink/2488a5ff6c314eddba50b0a6932c72d9 to your computer and use it in GitHub Desktop.
<template>
<nav>
<a :class="isUrl('') ? 'active' : 'not-active'" href="/">Dashboard</a>
<a :class="isUrl('users') ? 'active' : 'not-active'" href="/users">Users</a>
<a :class="isUrl('reports') ? 'active' : 'not-active'" href="/reports">Reports</a>
</nav>
</template>
<script>
export default {
methods: {
isUrl(...urls) {
if (urls[0] === '') {
return location.pathname.substr(1) === ''
} else {
return urls.filter(url => location.pathname.substr(1).startsWith(url)).length
}
},
},
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment