0

Hope all are doing good. I will directly move to the issue, I am trying to migrate my React-Typescript to Next JS for routing purpose. I am using Link -next/link but it is not working when the server is started but after a refresh routing is working fine. I am missing somewhere, could you please help me out?

<div>
      <Link href='/page1'  as={`/page1`}>
        <a>Page1</a>
      </Link>
      <p>Welcome to the page 2</p>
    </div>

After so many research I couldn't find anything in the interim, I randomly tried something, now the code is working as expected but I want to know how it is working. Below I have pasted the working code

<div>
      <Link href='/'  as={`/page1`}>
        <a>Page1</a>
      </Link>
      <p>Welcome to the page 2</p>
    </div>

I did nothing just did this href='/page1' to href='/' or href='/page1' to href='/page' From the above scenarios, I used only one, now routing is working properly. I am bit confused how it's working and I need proper explanation for this scenario. Please help me out. Thanks in advance

juliomalves
  • 42,130
  • 20
  • 150
  • 146
MONEYMSN
  • 69
  • 9
  • _"I am using Link -next/link but it is not working"_ - What do you mean by not working? What happens when you click the link exactly? – juliomalves Aug 26 '22 at 19:14
  • I am actually working in an e-commerce site where router are working in react but now we are trying to use next JS to improve the performance. We tried implementing next/link but when during the initial load the link Bills is not navigating to this page1. However, after refreshing or after routing directly in the url and then trying to use the link, then it is navigating as expected. – MONEYMSN Aug 30 '22 at 08:07

0 Answers0