I have a simple SPA and the App and About components are like below. When I click on About link, the about page appears under the links. The problem is that when I click on "About me" link, the "me" page loads instead of about page. What I really want is having nested routing in nextjs. It seems that first-level routes are loading in . But I don't know how to add it to my subcomponents.
import App, { Container } from 'next/app'
import React from 'react'
import Link from 'next/link'
class MyApp extends App {
static async getInitialProps({ Component, router, ctx }) {
let pageProps = {}
if (Component.getInitialProps) {
pageProps = await Component.getInitialProps(ctx)
}
return { pageProps }
}
render() {
const { Component, pageProps } = this.props
return <Container>
<ul>
<li><Link href="/news">News</Link></li>
<li><Link href="/about">About</Link></li>
</ul>
<Component{...this.props} />
</Container>
}
}
export default MyApp
import React from 'react'
import Link from 'next/link'
import Router from 'next/router'
class About extends React.Component {
render() {
return (
<div id="main">
<li><Link href="/about/company">About company</Link></li>
<li><Link href="/about/me">About me</Link></li>
</div>
)
}
}
export default About