Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
VisualDL
提交
fcd6d434
V
VisualDL
项目概览
PaddlePaddle
/
VisualDL
大约 1 年 前同步成功
通知
88
Star
4655
Fork
642
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
10
列表
看板
标记
里程碑
合并请求
2
Wiki
5
Wiki
分析
仓库
DevOps
项目成员
Pages
V
VisualDL
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
10
Issue
10
列表
看板
标记
里程碑
合并请求
2
合并请求
2
Pages
分析
分析
仓库分析
DevOps
Wiki
5
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
fcd6d434
编写于
9月 01, 2020
作者:
P
Peter Pan
提交者:
GitHub
9月 01, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: incorrect locale redirect (#780)
上级
b7220a01
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
20 addition
and
11 deletion
+20
-11
frontend/packages/i18n/src/middlewares/next-i18next-middleware.ts
.../packages/i18n/src/middlewares/next-i18next-middleware.ts
+11
-7
frontend/packages/i18n/src/utils/lng-path-corrector.ts
frontend/packages/i18n/src/utils/lng-path-corrector.ts
+9
-4
未找到文件。
frontend/packages/i18n/src/middlewares/next-i18next-middleware.ts
浏览文件 @
fcd6d434
...
...
@@ -17,9 +17,9 @@ const route = pathMatch();
export
default
function
(
nexti18next
:
NextI18Next
)
{
const
{
config
,
i18n
}
=
nexti18next
;
const
{
allLanguages
,
ignoreRoutes
,
localeSubpaths
}
=
config
;
const
{
allLanguages
,
ignoreRoutes
,
localeSubpaths
,
publicPath
}
=
config
;
const
isI18nRoute
=
(
req
:
Request
)
=>
ignoreRoutes
?.
every
(
x
=>
!
req
.
url
.
startsWith
(
x
));
const
isI18nRoute
=
(
req
:
Request
)
=>
ignoreRoutes
?.
every
(
x
=>
!
req
.
url
.
startsWith
(
(
publicPath
||
''
)
+
x
));
const
localeSubpathRoute
=
route
(
`/:subpath(
${
Object
.
values
(
localeSubpaths
||
{}).
join
(
'
|
'
)}
)(.*)`
);
const
middleware
=
[];
...
...
@@ -48,13 +48,17 @@ export default function (nexti18next: NextI18Next) {
*/
middleware
.
push
((
req
:
Request
,
res
:
Response
,
next
:
NextFunction
)
=>
{
if
(
isI18nRoute
(
req
)
&&
req
.
i18n
)
{
let
url
=
publicPath
?
req
.
url
.
replace
(
publicPath
,
''
)
:
req
.
url
;
if
(
!
url
)
{
url
=
'
/
'
;
}
let
currentLng
=
lngFromReq
(
req
);
const
currentLngSubpath
=
subpathFromLng
(
config
,
currentLng
);
const
currentLngRequiresSubpath
=
subpathIsRequired
(
config
,
currentLng
||
''
);
const
currentLngSubpathIsPresent
=
subpathIsPresent
(
req
.
url
,
currentLngSubpath
);
const
currentLngSubpathIsPresent
=
subpathIsPresent
(
url
,
currentLngSubpath
);
const
lngFromCurrentSubpath
=
allLanguages
.
find
((
l
:
string
)
=>
subpathIsPresent
(
req
.
url
,
subpathFromLng
(
config
,
l
))
subpathIsPresent
(
url
,
subpathFromLng
(
config
,
l
))
);
if
(
lngFromCurrentSubpath
!==
undefined
&&
lngFromCurrentSubpath
!==
currentLng
)
{
...
...
@@ -70,7 +74,7 @@ export default function (nexti18next: NextI18Next) {
If a language subpath is required and
not present, prepend correct subpath
*/
return
redirectWithoutCache
(
res
,
addSubpath
(
req
.
url
,
currentLngSubpath
));
return
redirectWithoutCache
(
res
,
(
publicPath
||
''
)
+
addSubpath
(
url
,
currentLngSubpath
));
}
/*
...
...
@@ -79,11 +83,11 @@ export default function (nexti18next: NextI18Next) {
render the correct route
*/
if
(
typeof
lngFromCurrentSubpath
===
'
string
'
)
{
const
params
=
localeSubpathRoute
(
req
.
url
);
const
params
=
localeSubpathRoute
(
url
);
if
(
params
!==
false
)
{
const
{
subpath
}
=
params
;
req
.
query
=
{...
req
.
query
,
subpath
,
lng
:
currentLng
};
req
.
url
=
removeSubpath
(
req
.
url
,
subpath
);
req
.
url
=
(
publicPath
||
''
)
+
removeSubpath
(
url
,
subpath
);
}
}
}
...
...
frontend/packages/i18n/src/utils/lng-path-corrector.ts
浏览文件 @
fcd6d434
...
...
@@ -7,7 +7,7 @@ import {Config} from '../../types';
const
parseAs
=
(
originalAs
:
string
|
undefined
,
href
:
any
)
=>
{
const
asType
=
typeof
originalAs
;
let
as
;
let
as
:
string
;
if
(
asType
===
'
undefined
'
)
{
as
=
formatUrl
(
href
,
{
unicode
:
true
});
...
...
@@ -37,7 +37,7 @@ const parseHref = (originalHref: any) => {
};
export
const
lngPathCorrector
=
(
config
:
Config
,
currentRoute
:
any
,
currentLanguage
:
string
)
=>
{
const
{
allLanguages
,
localeSubpaths
}
=
config
;
const
{
allLanguages
,
localeSubpaths
,
publicPath
}
=
config
;
const
{
as
:
originalAs
,
href
:
originalHref
}
=
currentRoute
;
if
(
!
allLanguages
.
includes
(
currentLanguage
))
{
...
...
@@ -46,6 +46,11 @@ export const lngPathCorrector = (config: Config, currentRoute: any, currentLangu
const
href
=
parseHref
(
originalHref
);
let
as
=
parseAs
(
originalAs
,
href
);
if
(
publicPath
)
{
const
url
=
parseUrl
(
as
);
url
.
pathname
=
url
.
pathname
.
replace
(
publicPath
,
''
);
as
=
formatUrl
(
url
);
}
/*
url.format prefers the 'url.search' string over
...
...
@@ -58,8 +63,8 @@ export const lngPathCorrector = (config: Config, currentRoute: any, currentLangu
Strip any/all subpaths from the `as` value
*/
Object
.
values
(
localeSubpaths
||
{}).
forEach
((
subpath
:
string
)
=>
{
if
(
subpathIsPresent
(
as
as
string
,
subpath
))
{
as
=
removeSubpath
(
as
as
string
,
subpath
);
if
(
subpathIsPresent
(
as
,
subpath
))
{
as
=
removeSubpath
(
as
,
subpath
);
}
});
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录