diff --git a/lib/isomorphic/create-routes.coffee b/lib/isomorphic/create-routes.coffee
index fc029c2298e9a..d31008f448d30 100644
--- a/lib/isomorphic/create-routes.coffee
+++ b/lib/isomorphic/create-routes.coffee
@@ -3,6 +3,7 @@ filter = require 'lodash/collection/filter'
sortBy = require 'lodash/collection/sortBy'
last = require 'lodash/array/last'
includes = require 'underscore.string/include'
+{ config } = require 'config'
module.exports = (pages, pagesReq) ->
templates = {}
@@ -12,6 +13,33 @@ module.exports = (pages, pagesReq) ->
handler: pagesReq './_template'
})
+ # Adds a handler for that will serve as a 404 Page
+ if config.notFound
+ templates.rootNotFound = Router.createNotFoundRoute({
+ name: 'root-not-found'
+ path: "*"
+ handler: pagesReq './_404'
+ parentRoute: templates.root
+ })
+
+ # Adds a handler for for pagination
+ if config.pagination
+ templates.rootPagination = Router.createRoute({
+ name: "root-pagination"
+ path: "page/:pageId"
+ parentRoute: templates.root
+ handler: pagesReq './_pagination'
+ })
+
+ # Adds a handler for for pages tagging
+ if config.tags
+ templates.rootTags = Router.createRoute({
+ name: "root-tags"
+ path: "tag/:tagId"
+ parentRoute: templates.root
+ handler: pagesReq './_tag'
+ })
+
# Arrange pages in data structure according to their position
# on the file system. Then use this to create routes.
#
@@ -45,6 +73,15 @@ module.exports = (pages, pagesReq) ->
handler: pagesReq "./" + templateFile.requirePath
})
+ # Adds a handler for (for each templateFile) for pagination
+ if config.pagination
+ templates[templateFile.file.dirname + "-pagination"] = Router.createRoute({
+ name: templateFile.file.dirname + "-pagination"
+ path: templateFile.templatePath + "page/:pageId"
+ parentRoute: templates[templateFile.file.dirname]
+ handler: pagesReq "./" + templateFile.file.dirname + "/_pagination"
+ })
+
# Remove files that start with an underscore as this indicates
# the file shouldn't be turned into a page.
filteredPages = filter pages, (page) -> page.file.name.slice(0,1) isnt '_'
@@ -85,9 +122,17 @@ module.exports = (pages, pagesReq) ->
unless parentRoute
parentRoute = templates.root
+ if page.data and page.data.redirect
+ # Adds a handler for where page has a `redirect` metadata
+ Router.createRedirect({
+ name: page.path
+ from: page.path
+ to: page.data.redirect
+ parentRoute: parentRoute
+ })
# If page is an index page *and* in the same directory as a template,
# it is the default route (for that template).
- if includes(page.path, "/index") and
+ else if includes(page.path, "/index") and
parentRoute.file.dirname is parentTemplateFile.file.dirname
Router.createDefaultRoute({
name: page.path