Import All Exports As Object
Here's a technique for importing constants from a file:
import * as routes from './routes'
This wraps all the exports from routes.js
in the object routes
. We can access any of those constants like this:
<Route path={routes.exportedPath} />
I like this technique for this use case, because it keeps our import to one line and adds a meaningful namespace.
Tweet