<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ayushghetia on Medium]]></title>
        <description><![CDATA[Stories by Ayushghetia on Medium]]></description>
        <link>https://medium.com/@ayushghetia?source=rss-81ebc0da8302------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*i8vazt_n3SPVfHiJ771XZQ.jpeg</url>
            <title>Stories by Ayushghetia on Medium</title>
            <link>https://medium.com/@ayushghetia?source=rss-81ebc0da8302------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 07:28:07 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ayushghetia/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to use global after hooks in Vue]]></title>
            <link>https://medium.com/@ayushghetia/how-to-use-global-after-hooks-in-vue-70738abc8472?source=rss-81ebc0da8302------2</link>
            <guid isPermaLink="false">https://medium.com/p/70738abc8472</guid>
            <dc:creator><![CDATA[Ayushghetia]]></dc:creator>
            <pubDate>Thu, 06 Apr 2023 15:30:33 GMT</pubDate>
            <atom:updated>2023-04-25T13:19:24.606Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yOSZfDxSGi0pGOAvaf6kYA.jpeg" /></figure><p>Dear Developers, I am here to share a solution that can help you to overcome the NavigationDuplicated error that might occur during VueJS project development.</p><p>The error message that you may encounter is “Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to the current location”. To tackle this error, I suggest using Global Resolve Guards call Global After Hooks.</p><p>Below are the steps that you can follow to implement Global After Hooks and resolve the error:</p><ol><li>Firstly, in your main.js file, import the createRouter function from the Vue Router package.</li><li>Secondly, create an instance of the router using the createRouter function.</li><li>Next, add a global after hook to the router instance using the afterEach method.</li><li>Inside the after hook, check if the current route and the previous route are the same by using the currentRoute and from properties.</li><li>If both routes are the same, then use the back method of the router to navigate back to the previous page.</li></ol><p>By following these steps, you can effectively use Global After Hooks and avoid the NavigationDuplicated error.</p><p>Here’s a code snippet to achieve the above steps:</p><pre>import { createApp } from &#39;vue&#39;<br>import { createRouter, createWebHistory } from &#39;vue-router&#39;<br>import App from &#39;./App.vue&#39;<br>import ShippingLocation from &#39;./views/ShippingLocation.vue&#39;<br><br>const routes = [<br>  { path: &#39;/shipping-location&#39;, component: ShippingLocation }<br>]<br><br>const router = createRouter({<br>  history: createWebHistory(),<br>  routes<br>})<br><br>router.afterEach((to, from) =&gt; {<br>  if (to.path === from.path) {<br>    router.back()<br>  }<br>})<br><br>const app = createApp(App)<br>app.use(router)<br>app.mount(&#39;#app&#39;)</pre><p>In the example mentioned above, a global after hook was added to the router instance using the afterEach method. The after hook checks whether the current and previous routes are the same by using the to.path and from.path properties. If the routes are identical, the back method of the router is used to navigate back to the previous page.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=70738abc8472" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>