diff --git a/Composer/packages/client/src/utils/hooks.ts b/Composer/packages/client/src/utils/hooks.ts index a67abc4f9f..d206829d53 100644 --- a/Composer/packages/client/src/utils/hooks.ts +++ b/Composer/packages/client/src/utils/hooks.ts @@ -8,7 +8,13 @@ import find from 'lodash/find'; import { useRecoilValue } from 'recoil'; import { FeatureFlagKey } from '@bfc/shared'; -import { designPageLocationState, currentProjectIdState, pluginPagesSelector, featureFlagsState } from '../recoilModel'; +import { + designPageLocationState, + currentProjectIdState, + pluginPagesSelector, + featureFlagsState, + rootBotProjectIdSelector, +} from '../recoilModel'; import { bottomLinks, topLinks } from './pageLinks'; import routerCache from './routerCache'; @@ -50,10 +56,17 @@ export const useLinks = () => { }; export const useRouterCache = (to: string) => { + const rootProjectId = useRecoilValue(rootBotProjectIdSelector); const [state, setState] = useState(routerCache.getAll()); const { topLinks, bottomLinks } = useLinks(); const linksRef = useRef(topLinks.concat(bottomLinks)); linksRef.current = topLinks.concat(bottomLinks); + + useEffect(() => { + routerCache.cleanAll(); + setState({}); + }, [rootProjectId]); + useEffect(() => { globalHistory.listen(({ location }) => { const links = linksRef.current; diff --git a/Composer/packages/client/src/utils/routerCache.ts b/Composer/packages/client/src/utils/routerCache.ts index 36a78f9db7..08290d9d20 100644 --- a/Composer/packages/client/src/utils/routerCache.ts +++ b/Composer/packages/client/src/utils/routerCache.ts @@ -25,6 +25,11 @@ class RouterCache { this._all[linkTo] = uri; this.storage.set(KEY, this._all); } + + cleanAll() { + this._all = {}; + this.storage.set(KEY, this._all); + } } export default new RouterCache();