We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
This would be fallback plugin to fix refresh issue
import { PluginType, NavigatorPluginType } from '@karrotframe/plugin' import React, {createContext, useContext, useState} from 'react' export const ContextPersistentPathPlugin = createContext<{ guideMessage: any setGuideMessage: (guideMessage: string) => void }>(null as any) export const PersistentPathPluginProvider: React.FC = (props) => { const [guideMessage, setGuideMessage] = useState('') return ( <ContextPersistentPathPlugin.Provider value={{ guideMessage, setGuideMessage }}> {props.children} </ContextPersistentPathPlugin.Provider> ) } export const usePersistentPlugin = (): PluginType & { setGuideMessage: (params: string) => any; guideMessage: string; } => { const {guideMessage, setGuideMessage} = useContext(ContextPersistentPathPlugin) return { lifeCycleHooks: { onInsertScreenInstance: async (ctx) => { if(ctx.ptr === -1 && ctx.screenInstance.screenId !== '/' && ctx.screenInstances.length === 0) { const previousPathInfoString = localStorage.getItem('screenPath'); if (!previousPathInfoString) { setGuideMessage('Can not go back anymore') return; } const {currentScreenInstances, isMatchedPath } = JSON.parse(previousPathInfoString); const hasHistoryStack = isMatchedPath === ctx.screenInstance.screenId; if (!hasHistoryStack) { setGuideMessage('Can not go back anymore') localStorage.removeItem('screenPath'); return; } const previousScreenPathArr = Object.keys(currentScreenInstances).map(index => currentScreenInstances[index]); const screenPath = [...previousScreenPathArr, {...ctx.screenInstance, id: (previousScreenPathArr.length + 1).toString(), nestedRouteCount: 0}] ctx.options?.setScreenInstancePtr?.(-1 + previousScreenPathArr.length); ctx.options?.setScreenInstances?.(screenPath) } }, beforePush: async (ctx) => { const currentScreenInstances = ctx.screenInstances.reduce((acc: any, curr: any, index: number) => { acc = { ...acc, [index+1]: curr } return acc }, {}); const pathInfo = { currentScreenInstances, isMatchedPath: ctx.to } localStorage.setItem('screenPath', JSON.stringify(pathInfo)); } }, setGuideMessage, guideMessage } } export const persistentPathPlugin: NavigatorPluginType = { name: 'persistentPathPlugin', provider: PersistentPathPluginProvider, executor: usePersistentPlugin, }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
This would be fallback plugin to fix refresh issue
The text was updated successfully, but these errors were encountered: