Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

p0k3rface's avatar

Vue composition api - go to previous page

Hello, is there any similar function in composition api like router.goBack() or router.go(-1) ? so I can redirect user to previous page? in options api it works but for composition it is not a function

0 likes
6 replies
tykus's avatar
tykus
Best Answer
Level 104

You don't share any code, so I don't know what you've tried. Anyway, the useRouter function can be imported from vue-router and the back() method called like this:

import { useRouter } from 'vue-router'

const router = useRouter()
router.back()
p0k3rface's avatar

Error im getting is : Uncaught TypeError: router.back is not a function

Sinnbeck's avatar

@p0k3rface Can you see the difference?

const router = useRouter() //Tykus
const router = useRouter; //You
tykus's avatar

@p0k3rface it should be a function call; you missed the parentheses

const router = useRouter()

Please or to participate in this conversation.