NavigationDuplicated Navigating to current location ("/search") is not allowed
This happened to me when I had a router-link
pointing to the same route. e.g. /products/1
.
The user is able to click on the products, but if a product was already clicked (and the component view was already loaded) and the user attempts to click it again, the error/warning shows in the console.
You can learn more on the github issue..
Posva, one of the main contributors of vue-router suggests:
router.push('your-path').catch(err => {})
However, if you don't want to have a catch
block which does nothing, in order to solve the issue you can compare the router navigation with the current route and only navigate if they differ:
const path = `/products/${id}`
if (this.$route.path !== path) this.$router.push(path)
Note: $route
is an object provided by vue-router to every component. See The Route Object for more info.
How to solve Avoided redundant navigation to current location error in vue?
As I remember well, you can use catch clause after this.$router.push. Then it will look like:
this.$router.push("/admin").catch(()=>{});
This allows you to only avoid the error displaying, because browser thinks the exception was handled.
Vue: NavigationDuplicated: Avoided redundant navigation to current location but need to reload page
one way to fix is to add a timestamp to route`query
methods: {
clicked() {
this.$router.push({
path: this.getTo,
query: { timestamp: Date.now() } // changes every time when clicked called
})
}
},
Got Uncaught (in promise) NavigationDuplicated error on invalid credentials
Looks like decision was simple, as error.response has ref to the current page:
if ( error.response.config.url != '/api/auth/login' ) {
router.push('/login');
}
and that works for me...
vue-router — Uncaught (in promise) Error: Redirected from "/login" to "/" via a navigation guard
The error message is getting updated in the next version of vue-router. The error will read:
Redirected when going from "/login" to "/" via a navigation guard
Somewhere in your code, after being redirected to "/login", you are redirecting back to "/". And vue-router is complaining about. You'll want to make sure you only have one redirect per navigation action.
Related Topics
Javascript Json Parsing Error: Unexpected Token ' in Json At Position 1
How to Get the Average from Array of Objects
How to Hide Blinking Cursor in Input Text
How to Remove a File from the Filelist
How to Count Duplicate Value in an Array in JavaScript
Write to a Text or Json File in React With Node
How to Access Variables from Another File
How to Override the Onbeforeunload Dialog and Replace It With My Own
Prevent CSS Tooltip from Going Out of Page/Window
How to Fix Problem Closing Dropdown When I Click Outside It
React Use State to Show Otherwise Hide
Detect Click into Iframe Using JavaScript
Show 2 Items Per Row[React Native]
How to Set the Multi Sliders in One Page
Does JavaScript Guarantee Object Property Order
Enable Utf-8 Encoding for JavaScript
How to Remove All Li Element of Same Class Except First Li Element in Jquery or JavaScript