No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    [SOLVED] Newbie question: how to get a router reference?

    Help
    3
    5
    1184
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      Marco last edited by Marco

      How can I get a router reference inside a click handler ?

      <template>
        <div>
            <q-btn color="primary" label="Submit" @click="onClick" />
        </div>
      </template>
      
      <script lang="ts">
      
      export default {
          setup() {
      
          function onClick() {
              console.log('onClick'); 
              //router.replace({ path: '/home' })       
          }
      
          return { onClick };
        }
      }
      </script>
      
      dobbel metalsadman 2 Replies Last reply Reply Quote 0
      • dobbel
        dobbel last edited by

        This post is deleted!
        1 Reply Last reply Reply Quote 0
        • dobbel
          dobbel @Marco last edited by

          @marco

          here’s a thread about it:
          https://forum.quasar-framework.org/topic/3960/access-router-outside-vue/7

          Easy answer is use the options API instead and you can do:

          this.$router
          
          1 Reply Last reply Reply Quote 0
          • metalsadman
            metalsadman @Marco last edited by

            @marco are you using Quasar v2? then see this https://next.router.vuejs.org/guide/advanced/composition-api.html.
            otherwise see the thread that @dobbel linked above.

            M 1 Reply Last reply Reply Quote 0
            • M
              Marco @metalsadman last edited by

              Thanks @metalsadman

              Now it works!
              My lack of understanding how next.router works.

              <script lang="ts">
              
              import { defineComponent } from 'vue'
              import { useRouter, useRoute } from 'vue-router'
              
              export default defineComponent({
                setup() {
              
                  const router = useRouter()
                  const route = useRoute()
              
                  function onClick() {
                      router.push({
                      path: '/home'
                    })     
                  }
              
                  return { onClick };
                }
                })
              </script>
              
              
              1 Reply Last reply Reply Quote 1
              • First post
                Last post