mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +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 (
|
} else if (
|
||||||
request.json || response.redirect
|
request.json || response.redirect
|
||||||
|| request.query.noTemplate || !response.template // no template, send raw data
|
|| request.query.noTemplate || !response.template // no template, send raw data
|
||||||
|| request.query._ui_next) { // for ui-next, we always send json
|
) {
|
||||||
// Send raw data
|
// Send raw data
|
||||||
try {
|
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());
|
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('pagename')) {
|
||||||
if (inject.includes('usercontext')) response.body.UserContext = user;
|
ctx.set('x-hydro-page', ctx._matchedRouteName || '');
|
||||||
}
|
}
|
||||||
if (request.query._ui_next) {
|
if (response.body !== null && typeof response.body === 'object') {
|
||||||
response.body = {
|
if (inject.includes('uicontext')) response.body.UiContext = UiContext;
|
||||||
// `_matchedRouteName` is koa-router's internal property, but it works,
|
if (inject.includes('usercontext')) response.body.UserContext = user;
|
||||||
// maybe we should migrate to a more official solution in the future.
|
if (inject.includes('routemap')) response.body.routeMap = handler.ctx.server.routeMap;
|
||||||
name: ctx._matchedRouteName,
|
}
|
||||||
args: response.body || {},
|
|
||||||
url: ctx.req.url,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
response.body = JSON.stringify(response.body, serializer(false, handler));
|
response.body = JSON.stringify(response.body, serializer(false, handler));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import React, { createContext, useCallback, useContext, useEffect, useMemo, useReducer, useRef } from 'react';
|
import React, { createContext, useCallback, useContext, useEffect, useMemo, useReducer, useRef } from 'react';
|
||||||
import { isSameOrigin } from '../utils/url';
|
import { isSameOrigin } from '../utils/url';
|
||||||
import { type PageData, useSetPageData } from './page-data';
|
import { useSetPageData } from './page-data';
|
||||||
|
|
||||||
interface InternalState {
|
interface InternalState {
|
||||||
status: 'idle' | 'loading' | 'error';
|
status: 'idle' | 'loading' | 'error';
|
||||||
@@ -57,7 +57,7 @@ export const RouterProvider: React.FC<React.PropsWithChildren> = ({ children })
|
|||||||
signal: controller.signal,
|
signal: controller.signal,
|
||||||
headers: {
|
headers: {
|
||||||
Accept: 'application/json',
|
Accept: 'application/json',
|
||||||
'x-hydro-inject': 'uicontext,usercontext',
|
'x-hydro-inject': 'uicontext,usercontext,pagename',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
if (res.redirected) {
|
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 a newer fetch has started, ignore this result
|
||||||
if (gen !== genRef.current) return false;
|
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' });
|
dispatch({ type: 'FETCH_SUCCESS' });
|
||||||
return true;
|
return true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
Reference in new issue
Block a user