其他分享
首页 > 其他分享> > vue3.x报警告:Path “/“ was passed with params but they will be ignored. Use a named route alongside ...

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'
		}
	}]
})

标签:ignored,Use,vue,name,params,they,home,path,Home
来源: https://blog.csdn.net/qq_43072786/article/details/121204960