Mastering Vue3: A Step-by-Step Guide to Using vue-router for Page Redirection

Clovon
Feb 25, 2023

--

First of all we need to import the function called useRouter from the vue-router plugin

import { useRouter} from 'vue-router';

The useRouter function provides us with a convenient way to access the Vue router instance and perform redirects to different pages. Let's assign the result of useRouter function to the constant called router

const router = useRouter();

Finally, we can use this router to navigate between pages. Example:

const handleSubmit = () => {
axios.post('/api/appointments/create', form)
.then((response) => {
router.push('/admin/appointments');
});
};

--

--

Clovon
Clovon

Written by Clovon

0 Followers

Web Development Mastery

No responses yet