Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[doc]: Tapping into Routes #3110

Open
aagasi opened this issue Apr 7, 2021 · 7 comments
Open

[doc]: Tapping into Routes #3110

aagasi opened this issue Apr 7, 2021 · 7 comments
Labels
documentation This pertains to documentation. Progress: ready for grooming

Comments

@aagasi
Copy link
Contributor

aagasi commented Apr 7, 2021

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 aagasi added the documentation This pertains to documentation. label Apr 7, 2021
@m2-assistant
Copy link

m2-assistant bot commented Apr 7, 2021

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


@sirugh
Copy link
Contributor

sirugh commented Apr 7, 2021

@magento export issue to JIRA project PWA as Task

@github-jira-sync-bot
Copy link

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

@supernova-at
Copy link
Contributor

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.

@evan-burrell
Copy link
Contributor

@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

@Jordaneisenburger
Copy link
Member

@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.

@rvr31
Copy link

rvr31 commented Jan 25, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation This pertains to documentation. Progress: ready for grooming
Projects
None yet
Development

No branches or pull requests

7 participants