分离设置页面

This commit is contained in:
IndieKKY
2024-10-04 19:14:01 +08:00
parent 46955e0a59
commit e238d83f78
9 changed files with 96 additions and 66 deletions

View File

@@ -1,15 +1,19 @@
import App from './App'
import {useEventEmitter} from 'ahooks'
import React from 'react'
import React, { useEffect } from 'react'
import { useAppDispatch } from './hooks/redux'
import { setPath } from './redux/envReducer'
export const EventBusContext = React.createContext<any>(null)
const map: { [key: string]: string } = {
'/options.html': 'options',
// '/close': 'close',
}
const Router = () => {
const path = map[window.location.pathname] ?? 'app'
const dispatch = useAppDispatch()
if (path === 'close') {
window.close()
@@ -18,8 +22,12 @@ const Router = () => {
// 事件总线
const eventBus = useEventEmitter()
useEffect(() => {
dispatch(setPath(path as 'app' | 'options'))
}, [dispatch, path])
return <EventBusContext.Provider value={eventBus}>
{path === 'app' && <App/>}
{(path === 'app' || path === 'options') && <App/>}
</EventBusContext.Provider>
}