shakee93 / vue-toasted

🖖 Responsive Touch Compatible Toast plugin for VueJS 2+
https://shakee93.github.io/vue-toasted/
MIT License
2.21k stars 194 forks source link

support router-link in toasts #18

Closed miladr closed 7 years ago

miladr commented 7 years ago

Please add support of router-link in toasts. For example when creating a user named "Milad", toast text should be "User Milad created successfully" and "Milad" should be linked to "users/10".

shakee93 commented 7 years ago

You can use this.$router.resolve({ name : 'your-route-name', params : { user_id : 10 } }).href to get the url of the route. take a look at official docs here router.resolve : http://router.vuejs.org/en/api/router-instance.html

miladr commented 7 years ago

I know that but using <a href="/users/10">Milad</a> causes page refresh.

shakee93 commented 7 years ago

Oh yes !! that will be a problem. the toast doesnt use the vue template engine it just uses plain javascript to build the html content. ill take a look if that is possible to make the component work.

although on your case you can attach an event listener to the <a> and use the vue-router push method to navigate to the location.

let toast = this.$toasted
    .show('<p>User <a href="">Milad</a> Successfully Created !!</p>');

toast.el
    .getElementsByTagName('a')[0]
    .addEventListener('click', (e) => {
        e.preventDefault();

        // in here redirect the user via $router
})

hope that helps. PR's are always welcome

miladr commented 7 years ago

Do you think using "slot" is an option?

shakee93 commented 7 years ago

Yeah it can be option if it is built via the vue template engine. but the toast is generated by plain javascript. thats the problem.

shakee93 commented 7 years ago

and also please take a look at globalToasts feature. if the problem is reusing the toast again and again with that large code. this might help to resolve it.

https://github.com/shakee93/vue-toasted#reusable-global-toasts