我在我的项目中使用 vue-router。
我能够完美导航到我指定的路线。我唯一的问题是,当我使用需要参数的命名路由时,刷新页面时它不会加载。
这是我的路线:
'/example/:username': {
name: 'example-profile',
title: 'Example Profile',
component: ExampleComponent
}
这就是我使用的方式vue-router
route
:
<a v-link="{ name: 'example-profile', params: { username: raaaaf } }">
Example Link
</a>
当我选择Example Link
I get mydomain.com/example/raaaaf
.
第一次加载时,它会呈现正确的模板,但是当我刷新或手动输入地址栏上的链接时,我会被重定向到我的Page Not Found
页面和创建页面时调用的方法不会被触发。
这就是我的ExampleComponent
:
<template>
<div class="small-12 left">
<side-bar></side-bar>
<div class="store-right">
<store-details></store-details>
<store-menu></store-menu>
<store-listings></store-listings>
</div>
</div>
</template>
<script>
export default {
data() {
return {
username: null,
user: null,
}
},
created() {
this.getUser()
},
methods: {
getUser() {
console.log(this.$route.params);
}
}
}
</script>