magento / pwa-studio

🛠Development tools to build, optimize and deploy Progressive Web Applications for Magento 2.
https://developer.adobe.com/commerce/pwa-studio/
Open Software License 3.0
1.07k stars 683 forks source link

[bug]: Can't load the same component for multiple routes #2914

Closed KevinGorjan closed 3 years ago

KevinGorjan commented 3 years ago

Describe the bug Hi all. I'm developing a package where I need that creates multi URLs but load the same components. This is needed for the side-menu I need.

targets.of("@magento/venia-ui")
  .routes
  .tap(routes => {
    routes.push({
      name: "Customer data",
      pattern: "/customer",
      path: Account,
      exact: true
    });
    routes.push({
      name: "Customers orders",
      pattern: "/customer/orders",
      path: Account,
      exact: true
    });
 return routes;
});

But when I re-start the development server, I receive this error

Error: @magento/venia-ui: Conflict in "routes" target. "@magento/venia-ui" is trying to add a route {"name":"Customers orders","pattern":"/customer/orders","path":"src/@project/overrides/lib/RootComponents/Account/index.js","exact":true}, but "@magento/venia-ui" has already declared another pattern for that same module: {"name":"Customer data","pattern":"/customer","path":"src/@project/overrides/lib/RootComponents/Account/index.js","exact":true,"requestor":"@magento/venia-ui"}

But when I load a new component for Customers orders, it can compile, but that's not what I need :-)

To reproduce

Expected behavior To load the same component with multiple URLs

Please complete the following device information:

Please let us know what packages this bug is in regards to:

m2-assistant[bot] commented 3 years ago

Hi @KevinGorjan. 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 commented 3 years ago

I asked Kevin to open the issue so we could document this incase folks run into the problem in the future as it is fixed on develop and should be fixed in the upcoming v9 release.

Just to check, I added a route to the top of defaultRoutes.json, which duplicated the AccountInformationPage with a different name and pattern. It worked and I was able to use both /account and /account-information to reach the same component!


[
    {
        "name": "Account",
        "pattern": "/account",
        "exact": true,
        "path": "../AccountInformationPage"
    },
    ...
]