boolean-uk / software-developer

0 stars 0 forks source link

Change paths to make them easier to generate programmatically #125

Open glowkeeper opened 1 year ago

glowkeeper commented 1 year ago

The react slides (and GitHub repos) currently suggest paths like:

/people/:id/edit

...but they're a pain to generate automagically. Better is:

/people/edit/:id

Because then you can do things like

const peopleEdit = '/people/edit'
const peopleEditId = '/people/edit/:id'

// or, better still 
const UIPaths = {
  peopleEdit: '/people/edit',
  peopleEditId = '/people/edit/:id'
}

And subsequently, build your paths programmatically, like so:

<Route path={UIPaths.peopleEditId}... />

<Link to=`${UIPaths.peopleEdit}/${id}`... />

Stringbuilding is an extremely important topic that doesn't get the attention it needs. The result is that, often, a large codebase becomes an unholy-hard-to-maintain mess because it's littered with magic strings: /people/:id/edit encourages that unholy mess, whereas /people/edit/:id does not. So an extra bit of quality we can add to the Boolean slides is to encourage the latter.