connected-react-router#LOCATION_CHANGE TypeScript Examples

The following examples show how to use connected-react-router#LOCATION_CHANGE. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: reducers.ts    From msteams-meetings-template with MIT License 6 votes vote down vote up
meetingReducer = (
  state: MeetingState,
  action: MeetingAction | LocationChangeAction<LocationChangePayload>
) => {
  if (!state) return loadInitialState();
  switch (action.type) {
    case SET_MEETING_COMMAND:
      return {
        ...state,
        inputMeeting: _.cloneDeep(action.meeting)
      };
    case CREATE_MEETING_COMMAND:
      return {
        ...state,
        creationInProgress: true
      };
    case MEETING_CREATED_EVENT:
      return {
        ...state,
        createdMeeting: action.meeting
      };
    case LOCATION_CHANGE:
      if (action.payload.location.pathname === '/createMeeting') {
        return {
          ...state,
          creationInProgress: false
        };
      }
    // falls through
    default:
      return state;
  }
}
Example #2
Source File: router.tsx    From reactant with MIT License 6 votes vote down vote up
constructor(@inject(RouterOptions) protected options: IRouterOptions) {
    super();
    const { autoProvide = true, stateKey = 'router' } = this.options || {};
    this.autoProvide = autoProvide;
    this.stateKey = stateKey;
    this.autoCreateHistory = this.options?.autoCreateHistory ?? true;
    if (this.autoCreateHistory) {
      this.history = this.options.createHistory();
      this.middleware = (store) => (next) => (action: RouterAction) => {
        if (action.type !== CALL_HISTORY_METHOD) {
          if (
            action.type === LOCATION_CHANGE &&
            action?.payload?.isFirstRendering === false &&
            this.history.location !== action.payload.location
          ) {
            this.history.replace(action.payload.location);
          }
          return next(action);
        }
        const {
          payload: { method, args = [] },
        } = action;
        const history: Record<string, Function> = this.history as any;
        history[method](...args);
      };
    }
  }