Created
January 10, 2019 18:20
-
-
Save AndrewIngram/26d7af3ee4a5ce6818ba1c50726db5b9 to your computer and use it in GitHub Desktop.
Basic router on top of Next.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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