如何分析 SAP Spartacus 路由問題之 CheckoutAuthGuard 單步除錯

i042416發表於2021-06-16

This document is written based on Spartacus 3.1.1.

The standard Storefront is used which is generated by Spartacus Schematics.

Suppose I would like to debug the executing of CheckoutAuthGuard for standard checkout step:Delivery Mode.


如何分析 SAP Spartacus 路由問題之 CheckoutAuthGuard 單步除錯


It means I need to set some breakpoint in the step BEFORE Delivery Mode, in this case it is Shipping address step, and then click "Continue" button to trigger the breakpoint.

in your project, expand folder node_modules/@spartacus:


如何分析 SAP Spartacus 路由問題之 CheckoutAuthGuard 單步除錯


then storefront/fesm2015, find file spartacus-storefront.js:


如何分析 SAP Spartacus 路由問題之 CheckoutAuthGuard 單步除錯


Search by key word "CheckoutDeliveryMode", which is the default CMS component for Delivery Mode checkout step.

You see line 11037, the two standard component guard, CheckoutAuthGuard and CartNotEmptyGuard are defined there.

Add some product to carts, then open url:

open Chrome Development tool,switch to Sources tab,press Ctrl+ O,type spa, then select spartacus-storefront.js from search list:


如何分析 SAP Spartacus 路由問題之 CheckoutAuthGuard 單步除錯


then search by keyword CheckoutAuthGuard:


如何分析 SAP Spartacus 路由問題之 CheckoutAuthGuard 單步除錯


and set breakpoint in method canActivate.

Let's say if a checkout Component has configured Component guards A,B,C, only if all guards return true intheir canActivate method, then the corresponding checkout step page could be opened.

In my case I press "continue" button in Shipping Address page, then breakpoint is triggered.


如何分析 SAP Spartacus 路由問題之 CheckoutAuthGuard 單步除錯


then you can debug to check the guard execution.


如何分析 SAP Spartacus 路由問題之 CheckoutAuthGuard 單步除錯


As mentioned by document, canActivate method is expected to return true to achieve the routing of next checkout step.


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24475491/viewspace-2776909/,如需轉載,請註明出處,否則將追究法律責任。

相關文章