When migrating an Aurelia 1 application to Aurelia 2 recently, I had to deal with many routes I needed to convert tediously. As you might have discovered, the Aurelia 2 @aurelia/router
is different to the Aurelia 1 router.
Not wanting to change 50+ manual PLATFORM.moduleName
values, I opted for a regular expression. I hate RegEx because I don’t understand it, but you cannot deny its power. Here’s the solution I used.
- Find: PLATFORM.moduleName(‘(.*)’)
- Replace: () => import(‘$1’)
This will take: PLATFORM.moduleName(‘pages/about-us/about-us’) and convert it to: () => import(‘pages/about-us/about-us’)
Little warning: it is possible to have the result from an expression as module name. In that case you might end up with a strange result (because of the greedyness of `.*` and the `’)` at the end.
But if only straight strings or simple string + string expressions are used, this should result in a correct transformation. 👍