mirror of https://github.com/alibaba/ice.git
fix: do not log warning message when use router api (#6731)
This commit is contained in:
parent
2a99862677
commit
b85feaae6a
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'@ice/runtime': patch
|
||||
---
|
||||
|
||||
fix: do not log warning message when use router api
|
||||
|
|
@ -7,6 +7,7 @@ import App from './App.js';
|
|||
import { DataContextProvider } from './singleRouter.js';
|
||||
import { useAppContext } from './AppContext.js';
|
||||
import { setHistory } from './history.js';
|
||||
import { disableHistoryWarning } from './utils/deprecatedHistory.js';
|
||||
|
||||
function createRouterHistory(history: History, router: Router) {
|
||||
const routerHistory = history;
|
||||
|
|
@ -39,6 +40,7 @@ function ClientRouter(props: ClientAppRouterProps) {
|
|||
clearRouter();
|
||||
// @ts-expect-error routes type should be AgnosticBaseRouteObject[]
|
||||
router = createRouter(routerContext).initialize();
|
||||
disableHistoryWarning();
|
||||
// Replace history methods by router navigate for backwards compatibility.
|
||||
setHistory(createRouterHistory({ ...routerContext.history }, router));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,24 @@
|
|||
import type { History, To } from '@remix-run/router';
|
||||
|
||||
let disableWarning = false;
|
||||
|
||||
export function disableHistoryWarning() {
|
||||
disableWarning = true;
|
||||
}
|
||||
|
||||
export function deprecatedHistory(history: History) {
|
||||
const originHistory = { ...history };
|
||||
const deprecatedMessage = 'history.push and history.replace is not recommended to use outside of react component. The usage will be deprecated in the next minor version.';
|
||||
history.push = function (to: To, state?: any) {
|
||||
console.warn(deprecatedMessage);
|
||||
if (!disableWarning) {
|
||||
console.warn(deprecatedMessage);
|
||||
}
|
||||
originHistory.push(to, state);
|
||||
};
|
||||
history.replace = function (to: To, state?: any) {
|
||||
console.warn(deprecatedMessage);
|
||||
if (!disableWarning) {
|
||||
console.warn(deprecatedMessage);
|
||||
}
|
||||
originHistory.replace(to, state);
|
||||
};
|
||||
return history;
|
||||
|
|
|
|||
Loading…
Reference in New Issue