pwa-studio icon indicating copy to clipboard operation
pwa-studio copied to clipboard

[doc]: Tapping into Routes

Open aagasi opened this issue 3 years ago • 7 comments

Describe the request In the same way we tap into the routes to "push" new routes we can also change the default routes defined in /packages/venia-ui/lib/defaultRoutes.json

Possible solutions How would you word this addition or change?

Screenshots As we can see in the following image, makeRoutesTarget() initializes the Routes component. As part of this initialization if we have a target interceptor that "pushes" new routes to the routes array they will be added. Therefore in the routeList variable we'll have all those custom routes. After this, addRoutes(routeList, require('../defaultRoutes.json')) method is called with 2 params. The 2nd params is an array of default routes pre-defined for pwa. image

If we need to edit some of the default pre-defined routes we can do it in our custom interceptor by tapping into routes target and specifiying the "pattern" that we want to update (see following image): image

In the prior example, the "/communications" route is being updated to redirect to 404 whenever someone tries to access it.

aagasi avatar Apr 07 '21 19:04 aagasi

Hi @aagasi. Thank you for your report. To help us process this issue please make sure that you provided sufficient information.

Please, add a comment to assign the issue: @magento I am working on this


m2-assistant[bot] avatar Apr 07 '21 19:04 m2-assistant[bot]

@magento export issue to JIRA project PWA as Task

sirugh avatar Apr 07 '21 19:04 sirugh

:white_check_mark: Jira issue (https://jira.corp.magento.com/browse/PWA-1664) is successfully created for this issue.

github-jira-sync-bot avatar Apr 07 '21 19:04 github-jira-sync-bot

Hi @aagasi , thanks for reporting this.

We have just triaged it and assigned it to an upcoming epic expanding extensibility. Unfortunately we do not have an estimate on when this will be completed at this time.

supernova-at avatar Apr 19 '21 16:04 supernova-at

@supernova-at

Would something like this suffice in @magento/venia-ui/lib/targets/makeRoutesTarget.js:

-    const routeList = venia.reactComponent(
+    venia.reactComponent(
         '@magento/venia-ui/lib/components/Routes/routes.js',
-        async ({ routes }, self) => addRoutes(self, await routes.promise([]))
+        async ({ routes }, self) => addRoutes(self, await routes.promise(require('../defaultRoutes.json')))
     );
-
-    // Add our own default routes!
-    addRoutes(routeList, require('../defaultRoutes.json'));
 }

Happy to make a PR for this

evan-burrell avatar May 11 '21 13:05 evan-burrell

@evan-burrell this is also an issue for a project I'm working on, your fix seems to resolve the issue and makes the routes tappable again.

Jordaneisenburger avatar Jan 24 '22 12:01 Jordaneisenburger

Well I guess the routes is already tappable and tapping does work, but it gets loaded twice. Once from the:

// Add our own default routes!
addRoutes(routeList, require('../defaultRoutes.json'));

That one is not tapable and will always load the default routes and add them. And once from the:

async ({ routes }, self) => addRoutes(self, await routes.promise([]))

Also containing the default routes. So removing or changing routes will always keep the original due the the extra untappable addRoutes.

rvr31 avatar Jan 25 '22 23:01 rvr31