Skip to content

Instantly share code, notes, and snippets.

@AndrewIngram
Created January 10, 2019 18:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndrewIngram/26d7af3ee4a5ce6818ba1c50726db5b9 to your computer and use it in GitHub Desktop.
Save AndrewIngram/26d7af3ee4a5ce6818ba1c50726db5b9 to your computer and use it in GitHub Desktop.
Basic router on top of Next.js
import { include, createRouter } from "./lib/router";
const commonRoutes = [
{
path: "/terms-of-business/",
name: "terms-of-business",
page: "TermsOfBusinessPage",
},
];
const esRoutes = [
include({ routes: commonRoutes }),
{
path: "/",
name: "homepage",
page: "HomepageEs",
},
];
const ieRoutes = [
include({ routes: commonRoutes }),
{
path: "/",
name: "homepage",
page: "HomepageIe",
},
];
const gbRoutes = [
include({ routes: commonRoutes }),
{
path: "/",
name: "homepage",
page: "HomepageGb",
},
];
const routeConfig = include({
routes: [
include({ routes: gbRoutes }),
include({
routes: ieRoutes,
prefix: "/ie/",
params: { language: "en", country: "ie" },
}),
include({
routes: esRoutes,
prefix: "/es/",
params: { language: "es", country: "es" },
}),
],
params: { language: "en", country: "gb" }, // Default to GB
});
export { routeConfig };
const router = createRouter({
routes: routeConfig,
});
export default router;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment