0

I'm struggling to find a way to render the path of the router-link dynamically, for example with the test variable. I'm trying to bind :to but unsuccessfully. I don't know if I can use the ternary operator in the binding as shown below:

<template>
  <div>
    <router-link
       :to="{ test ? '/success' : '/fail' }"
       tag="button"
       class="btn-next">
       <span class="btn-text">BUTTON</span>
    </router-link>
  </div>
</template>

<script> 
export default {
  // ...
  data: function() {
    return {
      test: false
    };
  }
}
</script>

1 Answer 1

3

Your solution is close (you don't need the curly brackets). It should look like this:

<router-link :to="test ? '/success' : '/fail'">

demo

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.