Check if a url is a known route to a next.js application ahead of time
https://www.npmjs.com/package/next-known-route
- Understanding internal vs external links during render or elsewhere in your application (like utils)
- SEO - no follow links to external sources.
- Any feature that requires a page manifest lookup.
- Dynamic navigation and route expressions matching.
No third party dependencies, this is all made possible by using internal parts of next router.
In _app add the following and return it from getInitialProps
``js
import { getRouteManifest, isKnownRoute } from 'next-known-route'
const MyApp = ()=>{
const internalRoute = isKnownRoute('/') // or whatever path you want to check aganst. Returns true|false
return ()
}
MyApp.getInitialProps = async (appContext) => {
const appProps = await App.getInitialProps(appContext);
const props = {
...appProps,
knownRoutes: getRouteManifest() // returns ['/_app','/','/[...slug]']
};
return props
}
`
Contributions are welcome.