I am trying to make a single-page application in Next.js, but I am starting to think this is not possible. Can anyone show me how?
My first attempt was to use a HashRouter:
<HashRouter>
<div>
<NavLink to="/">Home</NavLink>
<NavLink to="/purchaseComplete">Purchase Complete</NavLink>
</div>
<div>
<Route exact path="/" Component={Default} />
<Route path="/purchaseComplete" Component={PurchaseComplete} />
</div>
</HashRouter>
But in the browser I see "Invariant failed: Browser history needs a DOM"
I then tried to use a StaticRouter:
<StaticRouter location="/" context={staticContext}>
<div>
<NavLink to="/">Home</NavLink>
<NavLink to="/purchaseComplete">Purchase Complete</NavLink>
</div>
<div>
<Switch>
<Route exact path="/" Component={Default} />
<Route path="/purchaseComplete" Component={PurchaseComplete} />
</Switch>
</div>
</StaticRouter>
This renders the two links, but nothing happens when you click them.
In the Next.js tutorials, they talk about SPA's in the beginning, but then they only show you how to make apps with multiple pages.
I am starting to think it's not possible to build an SPA in Next.js. Can anyone confirm this? Or can someone show me how to build an SPA in Next.js?