Replies: 1 comment 2 replies
-
You're absolutely right. The current behavior of react-router and Remix is to assume that the argument passed to the This behavior is intentional and is documented in the React Router documentation:
However, there's a way to handle this scenario elegantly without resorting to You can leverage the fact that the Here's how you can use it: import { useNavigate } from 'react-router-dom';
const MyComponent = () => {
const navigate = useNavigate();
const handleClick = () => {
const absoluteUrl = 'https://absolute-url';
navigate(absoluteUrl, { replace: true });
};
return <button onClick={handleClick}>Navigate to Absolute URL</button>;
}; By setting This approach works seamlessly with both React Router and Remix, as they share the same underlying navigation logic. Note that this approach assumes that the absolute URL you're navigating to is within the same domain as your application. If you need to navigate to a different domain, you'll need to use Also, keep in mind that replacing the current history entry might not be desirable in all cases, as it can affect the user's ability to navigate back and forth in the browser history. In those cases, you can omit the |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
currently doing this in react router and remix will assume https://absolute-url is a pathname
Instead it should assume it is an absolute url if the string starts with https://
This is very useful if you have a an url to the current host and want to navigate to it without reloading the page. Currently you will have to do the following which will cause the page to reload, redownloading and reexecuting javascript
Beta Was this translation helpful? Give feedback.
All reactions