The error message “not implemented: navigation (except hash changes)” typically occurs when you are trying to use a method or feature related to navigation that is not supported or implemented in the current context.
One common scenario where this error can occur is when you are working with the History API, specifically methods like pushState()
, replaceState()
, or go()
. These methods allow you to manipulate the browser’s history stack, but they may not be available in all environments or browsers.
Here is an example that demonstrates the error in code:
// Trying to use pushState in a Node.js environment
const { history } = require('history');
history.pushState(null, '', '/new-path');
// This will throw the "not implemented: navigation" error
// Trying to use go in a web worker
self.history.go(-1);
// This will also throw the error
To resolve this issue, you should first check if the method or feature you are trying to use is supported in the current environment. For example, you can use feature detection to determine if the History API is available:
if (typeof window.history !== 'undefined' && typeof window.history.pushState === 'function') {
// Safe to use pushState()
}
If the feature is not available, you may need to consider alternative approaches or seek different methods for achieving your desired functionality. It’s also important to keep in mind that different browsers or environments may have varying levels of support for navigation-related features, so it’s important to test and handle such scenarios gracefully.