提交 daec40e8 authored 作者: vipcxj's avatar vipcxj

支持跳转api不自动拼接context path

上级 e1a65d56
......@@ -5,21 +5,21 @@ import config from '../utils/config';
const { contextPath } = config;
const makePath = (base, path) => {
const makePath = (base, path, withContext = true) => {
if (path.startsWith('/')) {
return `${contextPath}${path}`;
return withContext ? `${contextPath}${path}` : path;
}
const basePath = base.endsWith('/') ? base : `${base}/`;
return resolvePathname(path, basePath);
};
const processPath = (base, path) => {
const processPath = (base, path, withContext = true) => {
if (isString(path)) {
return makePath(base, path);
return makePath(base, path, withContext);
}
return {
...path,
pathname: makePath(base, path.pathname),
pathname: makePath(base, path.pathname, withContext),
};
};
......@@ -41,12 +41,12 @@ history.listen((loc) => {
location.hash = loc.hash;
});
export const push = (path, state) => {
return history.push(processPath(getHistoryBase(history), path), state);
export const push = (path, state, withContext = true) => {
return history.push(processPath(getHistoryBase(history), path, withContext), state);
};
export const replace = (path, state) => {
return history.replace(processPath(getHistoryBase(history), path), state);
export const replace = (path, state, withContext = true) => {
return history.replace(processPath(getHistoryBase(history), path, withContext), state);
};
export const go = (n) => {
......@@ -81,15 +81,15 @@ const getThisBase = (theThis) => {
}
};
export const thisPush = (theThis, pathOrLoc) => {
export const thisPush = (theThis, pathOrLoc, withContext = true) => {
checkThis(theThis);
const route = processPath(getThisBase(theThis), pathOrLoc);
const route = processPath(getThisBase(theThis), pathOrLoc, withContext);
return theThis.props.router.push(route);
};
export const thisReplace = (theThis, pathOrLoc) => {
export const thisReplace = (theThis, pathOrLoc, withContext = true) => {
checkThis(theThis);
const route = processPath(getThisBase(theThis), pathOrLoc);
const route = processPath(getThisBase(theThis), pathOrLoc, withContext);
return theThis.props.router.replace(route);
};
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论