Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix route insertion order #336

Merged
merged 1 commit into from
Mar 25, 2020
Merged

Fix route insertion order #336

merged 1 commit into from
Mar 25, 2020

Conversation

peterp
Copy link
Contributor

@peterp peterp commented Mar 25, 2020

The addRoutesToRouterTask function searches the routes file for <Router> and inserts a new route (1-by-1) directly below this line:

<Router>
   <NewRoute />

Since they're always added to the top, the order of routes is reversed. We switch it around since users of this function might expect routes to be inserted in the order that they are defined.

export const addRoutesToRouterTask = (routes) => {
const redwoodPaths = getPaths()
const routesContent = readFile(redwoodPaths.web.routes).toString()
const newRoutesContent = routes.reverse().reduce((content, route) => {
if (content.includes(route)) {
return content
}
return content.replace(/(\s*)\<Router\>/, `$1<Router>$1 ${route}`)
}, routesContent)
writeFile(redwoodPaths.web.routes, newRoutesContent, {
overwriteExisting: true,
})
}

Fixes #211

@peterp peterp changed the title Switch route order to make them natural Fix route insertion order Mar 25, 2020
@peterp peterp merged commit c776b17 into master Mar 25, 2020
mohsen1 pushed a commit to mohsen1/redwood that referenced this pull request Apr 12, 2020
@thedavidprice thedavidprice deleted the pp-reverse-route-order branch June 9, 2020 23:04
@thedavidprice thedavidprice added this to the unassigned-version milestone May 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants