quickest-silver
quickest-silver12mo ago

Use Navigation now working properly

const { replace } = useNavigation(); const handleRedirectToRegister = () => { replace("register"); } when click returining this intead of redirecting to register http://localhost:3000/login?to=%2Flogin%2Fregister
8 Replies
kapa.ai
kapa.ai12mo ago
Hi @jash.s. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- The replace method from useNavigation is used to replace the current entry on the history stack. It seems like you're trying to navigate to the "register" page from the "login" page. However, the URL you're seeing suggests that the "register" page is being treated as a subroute of the "login" page. Here's how you can use the replace method:
import { useNavigation } from "@refinedev/core";

const { replace } = useNavigation();

replace("register"); // It navigates to the `/register` page
import { useNavigation } from "@refinedev/core";

const { replace } = useNavigation();

replace("register"); // It navigates to the `/register` page
Source (https://refine.dev/docs/core/hooks/navigation/use-navigation/#replace) If you're still facing issues, it might be due to how your routes are structured. Make sure that "register" is not a subroute of "login". If "register" is indeed a subroute, you might need to adjust your routing structure or use a different method to navigate. If the issue persists, it might be a bug or a configuration issue. In such cases, it's recommended to check the official documentation or seek help from the community. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai12mo ago
<@1129363768661516329> kapa.ai is still learning and improving, please let us know how it did by reacting below
quickest-silver
quickest-silverOP12mo ago
@kapa.ai when i m changing in the browser url then it is working fine but when clicked then it is not
kapa.ai
kapa.ai12mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- It seems like there might be an issue with how the replace function is being called within your handleRedirectToRegister function. Here's how you can define and use the handleRedirectToRegister function:
import { useNavigation } from "@refinedev/core";

const { replace } = useNavigation();

const handleRedirectToRegister = () => {
replace("/register");
}

// Use the function in an event handler
<button onClick={handleRedirectToRegister}>Register</button>
import { useNavigation } from "@refinedev/core";

const { replace } = useNavigation();

const handleRedirectToRegister = () => {
replace("/register");
}

// Use the function in an event handler
<button onClick={handleRedirectToRegister}>Register</button>
Source (https://refine.dev/docs/core/hooks/navigation/use-navigation/#replace) If you're still facing issues, it might be due to how your routes are structured or how the event handler is set up. Make sure that the handleRedirectToRegister function is being called correctly when the button is clicked. If the issue persists, it might be a bug or a configuration issue. In such cases, it's recommended to check the official documentation or seek help from the community. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai12mo ago
<@1129363768661516329> kapa.ai is still learning and improving, please let us know how it did by reacting below
quickest-silver
quickest-silverOP12mo ago
this is not working as expected
relaxed-coral
relaxed-coral12mo ago
You may use router.push('/register'), I will try to figure out how to do it with useNavigation() until then
import { useRouter } from "next/router";

const router = useRouter();
const handleRedirectToRegister = () => {
router.push('/register')
}
import { useRouter } from "next/router";

const router = useRouter();
const handleRedirectToRegister = () => {
router.push('/register')
}
magic-beige
magic-beige12mo ago
Make sure you have Register route defined and its in the same block as login. Where you put unauthenticaed routes. From the path, it seems like register route is under authenticated routes