Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit82b6dbc

Browse files
authored
fix(router): pass the base option as an argument (#15)
* fix(router): pass the base option as an argumentClose#14* test: remove redundant cases
1 parent90b4f26 commit82b6dbc

File tree

5 files changed

+45
-13
lines changed

5 files changed

+45
-13
lines changed

‎generator/codemods/router/__testfixtures__/create-history.input.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,9 @@ const router = new VueRouter({
2020
routes
2121
});
2222

23+
newVueRouter({
24+
mode:'history',
25+
routes
26+
});
27+
2328
exportdefaultrouter;

‎generator/codemods/router/__testfixtures__/create-history.output.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@ const routes = [
1515
];
1616

1717
constrouter=createRouter({
18+
history:createWebHistory(process.env.BASE_URL),
19+
routes
20+
});
21+
22+
createRouter({
1823
history:createWebHistory(),
19-
base:process.env.BASE_URL,
2024
routes
2125
});
2226

‎generator/codemods/router/__testfixtures__/create-router.input.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,8 @@ const router = new VueRouter({
1919
routes
2020
});
2121

22+
newVueRouter({
23+
routes
24+
});
25+
2226
exportdefaultrouter;

‎generator/codemods/router/__testfixtures__/create-router.output.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import{createRouter}from'vue-router';
1+
import{createRouter,createWebHashHistory}from'vue-router';
22
importHomefrom'../views/Home.vue';
33

44
constroutes=[
@@ -15,7 +15,12 @@ const routes = [
1515
];
1616

1717
constrouter=createRouter({
18-
base:process.env.BASE_URL,
18+
history:createWebHashHistory(process.env.BASE_URL),
19+
routes
20+
});
21+
22+
createRouter({
23+
history:createWebHashHistory(),
1924
routes
2025
});
2126

‎generator/codemods/router/index.js

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,33 +28,47 @@ module.exports = function(fileInfo, api) {
2828
addImport(context,{imported:'createRouter'},'vue-router')
2929
newVueRouter.replaceWith(({ node})=>{
3030
// mode: 'history' -> history: createWebHistory(), etc
31+
lethistoryMode='createWebHashHistory'
32+
letbaseValue
3133
node.arguments[0].properties=node.arguments[0].properties.map(p=>{
3234
if(p.key.name==='mode'){
3335
constmode=p.value.value
34-
letinitializer
3536
if(mode==='hash'){
36-
initializer='createWebHashHistory'
37+
historyMode='createWebHashHistory'
3738
}elseif(mode==='history'){
38-
initializer='createWebHistory'
39+
historyMode='createWebHistory'
3940
}elseif(mode==='abstract'){
40-
initializer='createMemoryHistory'
41+
historyMode='createMemoryHistory'
4142
}else{
4243
console.error(
4344
`mode must be one of 'hash', 'history', or 'abstract'`
4445
)
4546
returnp
4647
}
47-
48-
addImport(context,{imported:initializer},'vue-router')
49-
returnj.objectProperty(
50-
j.identifier('history'),
51-
j.callExpression(j.identifier(initializer),[])
52-
)
48+
return
49+
}elseif(p.key.name==='base'){
50+
baseValue=p.value
51+
return
5352
}
5453

5554
returnp
5655
})
5756

57+
// add the default mode with a hash history
58+
addImport(context,{imported:historyMode},'vue-router')
59+
node.arguments[0].properties=node.arguments[0].properties.filter(
60+
p=>!!p
61+
)
62+
node.arguments[0].properties.unshift(
63+
j.objectProperty(
64+
j.identifier('history'),
65+
j.callExpression(
66+
j.identifier(historyMode),
67+
baseValue ?[baseValue] :[]
68+
)
69+
)
70+
)
71+
5872
returnj.callExpression(j.identifier('createRouter'),node.arguments)
5973
})
6074
removeExtraneousImport(context,localVueRouter)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp