乐趣区

关于前端:Spartacus-Storefront-里如何在-SmartEdit-访问环境下暂时禁用-Early-login

对于 Spartacus Early login 的性能,即如果以后客户没有登录,则显示 login page. 而不是显示原始页面。

有的客户冀望 Spartacus 在 SmartEdit 环境下预览时,临时禁掉这个性能。

首先,开发人员应该剖析与需要相干的所有结果并对平安威逼进行建模,而后思考是否承受它们,例如:

  1. 某些性能页面(例如 CPQ 配置器)在用户未登录时无奈失常工作。
  2. 可能会关上一个安全漏洞(例如,歹意用户可能模仿 / 伪造处于智能编辑环境,并可能关上仅限登录用户拜访的您商店的页面)。

无关编写自定义代码的提醒

须要笼罩办法 ProtectedRoutesGuard.canActivate(),以便在 SmartEdit 环境下始终返回 true。

要查看是否处于 SmartEdit 环境,须要应用办法 SmartEditLauncherService.isLaunchedInSmartEdit()

SmartEditLauncherService 的次要目标是查看以后应用程序是否在 SmartEdit 环境下运行,并提供相干的性能来治理与 SmartEdit 的交互。以下是对 SmartEditLauncherService 用法的具体介绍:

  1. 引入 SmartEditLauncherService:
    首先,在应用 SmartEditLauncherService 之前,您须要在 Spartacus 应用程序的相干组件或服务中引入它。您能够通过以下形式将 SmartEditLauncherService 导入到您的组件或服务中:

    import {SmartEditLauncherService} from '@spartacus/smartedit';
  2. 注入 SmartEditLauncherService:
    接下来,在组件或服务的构造函数中注入 SmartEditLauncherService:

    constructor(private smartEditLauncherService: SmartEditLauncherService) {}
  3. 查看是否在 SmartEdit 环境下:
    您能够应用 SmartEditLauncherService 的 isLaunchedInSmartEdit() 办法来查看以后应用程序是否在 SmartEdit 环境下运行。该办法返回一个布尔值,批示以后是否处于 SmartEdit 环境。示例如下:

    const isSmartEditLaunched = this.smartEditLauncherService.isLaunchedInSmartEdit();
    if (isSmartEditLaunched) {// 在 SmartEdit 环境下执行相干逻辑} else {// 在非 SmartEdit 环境下执行其余逻辑}

须要留神的是,SmartEditLauncherService 只在 Spartacus 与 SAP Commerce 后端进行 SmartEdit 集成时才会应用。如果您的应用程序不波及 SmartEdit 或与其余后端集成,SmartEditLauncherService 可能不会发挥作用。

退出移动版