MCPcopy Create free account
hub / github.com/react-static/react-static / recurseRoute

Function recurseRoute

packages/react-static/src/static/getRoutes.js:95–142  ·  view source on GitHub ↗
(route, parent)

Source from the content-addressed store, hash-verified

93 const pluginNormalizeRoute = plugins.normalizeRoute(state)
94
95 const recurseRoute = (route, parent) => {
96 // Normalize the route
97 let normalizedRoute = normalizeRoute(route, parent, pluginNormalizeRoute)
98
99 // we check an array of paths to see
100 // if route path already existings
101 const existingRoute = routesByPath[normalizedRoute.path]
102
103 // If the route has children, we do a depth-first recurse
104 if (normalizedRoute.children) {
105 normalizedRoute.children.forEach(childRoute =>
106 recurseRoute(childRoute, normalizedRoute)
107 )
108 }
109
110 // If the route exists
111 if (existingRoute) {
112 // If it is meant to replace any routes before it
113 if (!normalizedRoute.replace) {
114 // If not replacing, we need to merge the two
115 // routes together
116 Object.assign(existingRoute, normalizedRoute)
117 // Then make sure we're pointing to the exising route
118 normalizedRoute = existingRoute
119 }
120 }
121
122 delete normalizedRoute.children
123
124 // Register the route by path
125 routesByPath[normalizedRoute.path] = normalizedRoute
126
127 // Keep track of index and 404 routes existence
128 if (normalizedRoute.path === '/') {
129 hasIndex = true
130 }
131
132 if (is404Path(normalizedRoute.path)) {
133 has404 = true
134 }
135
136 if (normalizedRoute.path.indexOf('\\') !== -1) {
137 throw new Error(
138 'Plugins must return a normalized path for the `path` key of a route,' +
139 ' which is a path with / and not \\.'
140 )
141 }
142 }
143
144 routes.forEach(route => recurseRoute(route))
145

Callers 1

normalizeAllRoutesFunction · 0.85

Calls 2

is404PathFunction · 0.90
normalizeRouteFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…