0

In Sitecore JSS, we are defining the app name, Sitecore path etc in the below section:

<app name="GCP"              
sitecorePath="/sitecore/content/Home/JSS"              
appDatasourcesPath="/sitecore/content/Home/JSS/$name/Components"              
graphQLEndpoint="/sitecore/api/Test />

With the above settings, the routes and components that we create will be created in the Sitecore Path given above.

But I have a need to create routes in the separate paths for each module. Hence, I have to make the SitecorePath dynamic. Please let me know how can I achieve this, please help.

Thanks, Shakti

| improve this question | | | | |
  • You are using code first? You can use Sitecore first to achieve this – Hishaam Namooya Apr 1 at 6:55
0

It's not easy to create routes dynamically, you may need to overwrite inbuilt processors to achieve this.

When you build JSS app or deploy items the below import processes will be invoked, ".\App_Config\Sitecore\JavaScriptServices\Sitecore.JavaScriptServices.AppServices.config"

    <import>
        ...
        ...
        <processor type="Sitecore.JavaScriptServices.AppServices.Pipelines.Import.ProcessItems, Sitecore.JavaScriptServices.AppServices" resolve="true" />
        <processor type="Sitecore.JavaScriptServices.AppServices.Pipelines.Import.ProcessDictionary, Sitecore.JavaScriptServices.AppServices" resolve="true" />
        <processor type="Sitecore.JavaScriptServices.AppServices.Pipelines.Import.ProtectDeveloperItems, Sitecore.JavaScriptServices.AppServices" resolve="true" />
        <processor type="Sitecore.JavaScriptServices.AppServices.Pipelines.Import.RefreshIndexes, Sitecore.JavaScriptServices.AppServices" resolve="true" />
    </import>

To create dynamic paths for routes, you probably need check "ProcessItems" code.

But if you are planning to create all routes under a single app then you can create the respective tree structure in your JSS app to achieve this. Just add app path in your config and remaining can be created in your JSS app, replicate your expected folder/item structure in JSS app, this will create the similar structure in Sitecore.

enter image description here

| improve this answer | | | | |
0

If your client has SXA, or has a license that comes with SXA, then building your modules as JSS Sites under a JSS Tenant could be another way to solve this.

sitecore
  content
    JSS Tenant
       JSS Site 1 (Module 1)
         Home
         Settings
       JSS Site 2 (Module 2)
         Home
         Settings

When you deploy your app code, the components and templates will deploy to the tenant level, so you can share them between sites/modules. But, each site has exclusive control of settings like hostname, virtual path, etc.

| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.