Reviewing a React router component implemented with Mosaic for Mosaic
In any frontend or backend application, the router is a place which is one of the most important ones to make plugin-friendly, when using Mosaic. Any amount of routes can be added to it, if it is designed correctly.
This article will demonstrate a router design from @scandipwa/shopify project, which is written completely in Mosaic.
Source implementation
Let's see the router itself! It is also available on this link. This is exactly the form of the router at the moment of writing this article.
It is clearly visible that the router does not actually render any routes! It just provides several convenient points for modification with Mosaic runtime plugins: _beforeSwitchRenderList, _switchRenderList and _afterSwitchRenderList
A router is pointless without routes, right? So let's add a route to the one defined above! We will use the Mosaic runtime plugins for this purpose.
As you see, the plugin declaration file presented below modifies the namespace of the class above, a member called _switchRenderList of target kindmember-property
It implements a plugin (proxy) functionaddCartPage, which accepts the initial member - sorted render map _switchRenderList declared above, adds an additional item to that map and returns the modified value to the application.