I am using slug page directory with next.js.
My directory is
Pages
-Main
--[cat]
---[content].js
When i use next/link from another page to go content page it works and loads fine. But when i use some other link like main/cat/content inside from [content].js page, next.js changes url but not load page. If i reload the page new page shows correctly.
<li key={x.categoryid}>
<Link href={`/main/${x.caturl}/${x.contenturl}`} key={x.title}>
<a>
<span>{x.title}</span>
</a>
</Link>
</li>
this does not work as i said.
<li key={x.categoryid}>
<a href={`/main/${x.caturl}/${x.contenturl}`}>
<span>{x.title}</span>
</a>
</li>
this one works but will cause problems at build because of using a.
How can i use next/link correctly? Current scenario is changing url and scroll up to page.
Edit: [content].js page look like
export async function getServerSideProps({params}) {
const { cat,content}= params;
const https = require('https');
const main = await fetch('https://localhost:7715/api/content/'+params.cat+'/'+params.content+'', {method: "GET" });
if (main.status != 200) {
return {
redirect: {
destination: '/404',
permanent: false,
},
props: {
notFound: true
}
}
}
else{
const mycontent = await main.json();
return {
props: {
data: JSON.stringify(mycontent) ||null,
}
}
}
}
class Content extends React.Component {
constructor(props){
super(props);
const pageData = JSON.parse(props.data);
this.state ={
pageData : pageData,
}}
render(){
return(
<>
page title is {this.state.pageData.title}
</>
)
}
}