| 1234567891011121314151617181920212223242526272829303132333435 |
- /* eslint-disable no-unused-expressions */
- // RootNavigation.js
- import * as React from 'react';
- import { CommonActions, StackActions } from '@react-navigation/native';
- export const navigationRef = React.createRef();
- export function navigate(name, params) {
- navigationRef.current?.navigate(name, params);
- }
- export function replace(name, params) {
- navigationRef.current?.dispatch(StackActions.replace(name, params));
- }
- export function goBack() {
- if (navigationRef.current.getRootState().index > 0) {
- navigationRef.current?.goBack();
- }
- }
- export function reset(name, params) {
- navigationRef.current?.dispatch(
- CommonActions.reset({
- index: 0,
- key: null,
- routes: [
- {
- name,
- params,
- },
- ],
- })
- );
- }
|