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

fix(router): pass the base option as an argument#15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
haoqunjiang merged 2 commits intomasterfromfix/router-codemod
Apr 16, 2020
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,4 +20,9 @@ const router = new VueRouter({
routes
});

new VueRouter({
mode: 'history',
routes
});

export default router;
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,8 +15,12 @@ const routes = [
];

const router = createRouter({
history: createWebHistory(process.env.BASE_URL),
routes
});

createRouter({
history: createWebHistory(),
base: process.env.BASE_URL,
routes
});

Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,4 +19,8 @@ const router = new VueRouter({
routes
});

new VueRouter({
routes
});

export default router;
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
import { createRouter } from 'vue-router';
import { createRouter, createWebHashHistory } from 'vue-router';
import Home from '../views/Home.vue';

const routes = [
Expand All@@ -15,7 +15,12 @@ const routes = [
];

const router = createRouter({
base: process.env.BASE_URL,
history: createWebHashHistory(process.env.BASE_URL),
routes
});

createRouter({
history: createWebHashHistory(),
routes
});

Expand Down
34 changes: 24 additions & 10 deletionsgenerator/codemods/router/index.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -28,33 +28,47 @@ module.exports = function(fileInfo, api) {
addImport(context, { imported: 'createRouter' }, 'vue-router')
newVueRouter.replaceWith(({ node }) => {
// mode: 'history' -> history: createWebHistory(), etc
let historyMode = 'createWebHashHistory'
let baseValue
node.arguments[0].properties = node.arguments[0].properties.map(p => {
if (p.key.name === 'mode') {
const mode = p.value.value
let initializer
if (mode === 'hash') {
initializer = 'createWebHashHistory'
historyMode = 'createWebHashHistory'
} else if (mode === 'history') {
initializer = 'createWebHistory'
historyMode = 'createWebHistory'
} else if (mode === 'abstract') {
initializer = 'createMemoryHistory'
historyMode = 'createMemoryHistory'
} else {
console.error(
`mode must be one of 'hash', 'history', or 'abstract'`
)
return p
}

addImport(context, { imported: initializer }, 'vue-router')
return j.objectProperty(
j.identifier('history'),
j.callExpression(j.identifier(initializer), [])
)
return
} else if (p.key.name === 'base') {
baseValue = p.value
return
}

return p
})

// add the default mode with a hash history
addImport(context, { imported: historyMode }, 'vue-router')
node.arguments[0].properties = node.arguments[0].properties.filter(
p => !!p
)
node.arguments[0].properties.unshift(
j.objectProperty(
j.identifier('history'),
j.callExpression(
j.identifier(historyMode),
baseValue ? [baseValue] : []
)
)
)

return j.callExpression(j.identifier('createRouter'), node.arguments)
})
removeExtraneousImport(context, localVueRouter)
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp