mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +08:00
ui-next: remove _ui_next search param
This commit is contained in:
2 files changed
+18
-16
No files matched your search
+10
-13
@@ -77,22 +77,19 @@ export default (logger, xff, xhost) => async (ctx: KoaContext, next: Next) => {
|
||||
} else if (
|
||||
request.json || response.redirect
|
||||
|| request.query.noTemplate || !response.template // no template, send raw data
|
||||
|| request.query._ui_next) { // for ui-next, we always send json
|
||||
) {
|
||||
// Send raw data
|
||||
try {
|
||||
if (typeof response.body === 'object' && request.headers['x-hydro-inject']) {
|
||||
if (request.headers['x-hydro-inject']) {
|
||||
const inject = request.headers['x-hydro-inject'].toString().toLowerCase().split(',').map((i) => i.trim());
|
||||
if (inject.includes('uicontext')) response.body.UiContext = UiContext;
|
||||
if (inject.includes('usercontext')) response.body.UserContext = user;
|
||||
}
|
||||
if (request.query._ui_next) {
|
||||
response.body = {
|
||||
// `_matchedRouteName` is koa-router's internal property, but it works,
|
||||
// maybe we should migrate to a more official solution in the future.
|
||||
name: ctx._matchedRouteName,
|
||||
args: response.body || {},
|
||||
url: ctx.req.url,
|
||||
};
|
||||
if (inject.includes('pagename')) {
|
||||
ctx.set('x-hydro-page', ctx._matchedRouteName || '');
|
||||
}
|
||||
if (response.body !== null && typeof response.body === 'object') {
|
||||
if (inject.includes('uicontext')) response.body.UiContext = UiContext;
|
||||
if (inject.includes('usercontext')) response.body.UserContext = user;
|
||||
if (inject.includes('routemap')) response.body.routeMap = handler.ctx.server.routeMap;
|
||||
}
|
||||
}
|
||||
response.body = JSON.stringify(response.body, serializer(false, handler));
|
||||
} catch (e) {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import React, { createContext, useCallback, useContext, useEffect, useMemo, useReducer, useRef } from 'react';
|
||||
import { isSameOrigin } from '../utils/url';
|
||||
import { type PageData, useSetPageData } from './page-data';
|
||||
import { useSetPageData } from './page-data';
|
||||
|
||||
interface InternalState {
|
||||
status: 'idle' | 'loading' | 'error';
|
||||
@@ -57,7 +57,7 @@ export const RouterProvider: React.FC<React.PropsWithChildren> = ({ children })
|
||||
signal: controller.signal,
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
'x-hydro-inject': 'uicontext,usercontext',
|
||||
'x-hydro-inject': 'uicontext,usercontext,pagename',
|
||||
},
|
||||
});
|
||||
if (res.redirected) {
|
||||
@@ -72,7 +72,12 @@ export const RouterProvider: React.FC<React.PropsWithChildren> = ({ children })
|
||||
// If a newer fetch has started, ignore this result
|
||||
if (gen !== genRef.current) return false;
|
||||
|
||||
setData((prev) => (body.HYDRO_INJECTED ? body : { ...prev, ...body }));
|
||||
setData((prev) => ({
|
||||
...prev,
|
||||
args: body,
|
||||
name: pageName,
|
||||
url,
|
||||
}));
|
||||
dispatch({ type: 'FETCH_SUCCESS' });
|
||||
return true;
|
||||
} catch (e) {
|
||||
|
||||
Reference in new issue
Block a user