Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enclosing a router-link tag in a button in vuejs

Can I wrap or enclose a router-link tag in a button tag?

When I press the button, I want it to route me to the desired page.

like image 260
Kushagra Agarwal Avatar asked Aug 11 '17 14:08

Kushagra Agarwal


People also ask

Can we use router link in button?

If you need logic to occur before you go to a route you can import the Router Module and use it as such. I'm unsure of the best practice but I would say that it is fine to use routerLink and (click) in the same button as long as you do not interfere with the navigation. Manually navigation via this. router.

How do you link a button on Vue?

The appearance of the Button can be changed like a link by e-link class using cssClass property and link navigation can be handled in Button click. In the following example, link is added in Button click by using window. open() method.

How do I redirect a URL in Vue?

Suppose we have a /contact route in our vue app, when a user visits the /contact page we need to redirect them to an external url https://www.google.com/contact/ instead of the same domain redirect. To redirect to an external url in Vue, we can use the window. location. href property.


1 Answers

You can use tag prop.

<router-link to="/foo" tag="button">foo</router-link> 
like image 114
choasia Avatar answered Sep 23 '22 07:09

choasia