You've already forked bilibili-subtitle
分离设置页面
This commit is contained in:
@@ -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>
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user