Vue.js: Router-link with a function inside Vue.js: Router-link with a function inside vue.js vue.js

Vue.js: Router-link with a function inside


You can implement like this:

<template> <div @click="redirectUser(item.notification_type)">    <p>    <span v-html="item.message"></span>    </p> </div></template><script>export default {   props: ['item'],    methods: {     redirectUser (notificationType) {       if (notificationType === 'user_subscribed') {         this.$router.push('/your-custom-route')       } else if (notificationType === 'comment_created') {         this.$router.push('/awesome-comments')       }     }   }}</script>