Harmony HMRouter 通过拦截器判断页面的进入方式(push pop replace)

45 阅读1分钟
export class JumpInfoInterceptor implements IHMInterceptor {
  handle(info: HMInterceptorInfo): HMInterceptorAction {
    let connectionInfo: string = '';
    if(info.type === HMActionType.PUSH) {
      connectionInfo = 'jump to';
    } else {
      connectionInfo = 'back to';
    }

    console.log(`${info.srcName} ${connectionInfo} ${info.targetName}`);
    return HMInterceptorAction.DO_NEXT;
  }
}

这里主要是通过HMInterceptorInfo.type 来判断。type一共有三种

export declare class HMActionType {
    static POP: string;
    static PUSH: string;
    static REPLACE: string;
}