feat: 增加根路由注册

pull/81/head
moonrailgun 3 years ago
parent 5814c1f795
commit 20537788d6

@ -8,6 +8,7 @@ import { Helmet } from 'react-helmet';
import { useRecordMeasure } from './utils/measure-helper';
import { getPopupContainer, preventDefault } from './utils/dom-helper';
import { LoadingSpinner } from './components/LoadingSpinner';
import { pluginRootRouter } from './plugin/common';
const MainRoute = Loadable(() => import('./routes/Main'));
@ -76,6 +77,9 @@ export const App: React.FC = React.memo(() => {
<Route path="/main" component={MainRoute} />
<Route path="/panel" component={PanelRoute} />
<Route path="/invite/:inviteCode" component={InviteRoute} />
{pluginRootRouter.map((r) => (
<Route key={r.name} path={r.path} component={r.component} />
))}
<Redirect to="/entry" />
</Switch>
</AppContainer>

@ -1,19 +1,16 @@
import { getSearchParam } from '@/utils/location-helper';
import { useEffect, useState } from 'react';
const getValue = (search: string, param: string) =>
new URLSearchParams(search).get(param);
export type UseQueryParam = (param: string) => string | null;
export const useSearchParam: UseQueryParam = (param) => {
const location = window.location;
const [value, setValue] = useState<string | null>(() =>
getValue(location.search, param)
getSearchParam(param)
);
useEffect(() => {
const onChange = () => {
setValue(getValue(location.search, param));
setValue(getSearchParam(param));
};
window.addEventListener('popstate', onChange);

@ -144,3 +144,12 @@ export const [pluginMessageExtraParsers, regMessageExtraParser] = buildRegList<{
name: string;
render: (payload: ChatMessage) => React.ReactNode;
}>();
/**
*
*/
export const [pluginRootRouter, regRootRouter] = buildRegList<{
name: string;
path: string;
component: React.ComponentType;
}>();

@ -1,5 +1,5 @@
#tailchat-app {
@apply text-typography-light;
@apply text-typography-light bg-content-light;
--tc-background-image: url(../../assets/images/bg.jpg);
--tc-content-background-image: '';
@ -50,7 +50,7 @@
// 深色模式覆盖
&.dark {
@apply text-typography-dark;
@apply text-typography-dark bg-content-dark;
::-webkit-scrollbar-corner {
background-color: transparent;

@ -0,0 +1,6 @@
/**
* search
*/
export function getSearchParam(param: string): string | null {
return new URLSearchParams(window.location.search).get(param);
}
Loading…
Cancel
Save