vue3.x报警告:Path “/“ was passed with params but they will be ignored. Use a named route alongside ...

版本号:
vue/cli:4.5.12
@vue/cli-plugin-router: ~4.5.0

问题

以下写法会导致报警告:
[Vue Router warn]: Path "/" was passed with params but they will be ignored. Use a named route alongside params instead.
[Vue Router 警告]:路径“/”与参数一起传递,但它们将被忽略。改为在 params 旁边使用命名路由

const router = createRouter({
	history: createWebHashHistory(),
	routes: [{
	name: 'Home',
	path: '/',
	component: () => import( /* webpackChunkName: "home" */ '../views/home/index.vue'),
	},{
		path: '/:pathMatch(.*)',
		redirect: '/'
	}]
})

解决方案

const router = createRouter({
	history: createWebHashHistory(),
	routes: [{
	name: 'Home',
	path: '/',
	component: () => import( /* webpackChunkName: "home" */ '../views/home/index.vue'),
	},{
		path: '/:pathMatch(.*)',
		redirect: {
			name: 'Home'
		}
	}]
})
上一篇:c# – 比较谓词


下一篇:Python pip install报错:setup command: use_2to3 is invalid解决方法