ecosystem/vue-router-prefer-named-push
Prefer named route objects for Vue Router programmatic navigation.
| Default severity | Presets | Automatic fix | Options |
|---|---|---|---|
warning |
ecosystem |
No | None |
Applies to: JS/TS scripts in Vue SFCs; examples show the relevant Options API or script setup form.
Bad
router.push receives a path string that is tied to the current URL spelling.
<script setup lang="ts">
router.push("/settings");
</script>
Good
router.push receives a route object with the stable settings name.
<script setup lang="ts">
router.push({ name: "settings" });
</script>
Configuration (Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({}).withVue({
linter: {
"preset": "incremental",
"rules": {
"ecosystem/vue-router-prefer-named-push": "warn"
}
},
});
Then run vp run lint.