我对 router.push()
有问题。
只要我来自 “/”
,它就可以正常工作。但是,当我在某个 “/routeX”
上并想通过 “/routeY”
转到 this.$router.push({route: “/routeY” })
时,它会将浏览器中的网址相应地更新为 mypage.com/routeY,但是页面没有更新,一切都保持不变。
这是我用来进行路由的 Vue 组件:
<script lang="ts">
import { Component, Prop, Vue } from "vue-property-decorator";
import { Link } from "@/logic/VueComponentData";
import DetailsPage from "@/views/DetailsPage.vue";
import { PageType } from "@/logic/PageType";
@Component({ components: {} })
export default class RouteRequester extends Vue {
@Prop() link!: Link;
@Prop({ default: "white" }) color!: string;
private go() {
if (!this.exists()) {
const config = {
path: this.link.path[0] == "/" ? this.link.path : "/" + this.link.path,
component: this.getPageType(),
name: this.link.path,
props: { refKey: this.link.href }
};
this.$router.addRoute(config);
}
this.$router.push({name: this.link.path });
}
private exists() {
const name = this.link.path;
const link = this.$router.resolve({
name: name
});
if (link && link.href !== "/") {
return true;
}
return false;
}
private getPageType() {
switch (this.link.pageType) {
case PageType.DETAILSPAGE:
return DetailsPage;
default:
throw new Error("not impled");
}
}
}
</script>
非常感谢帮助!!! -祝福,尼科
PS:我也把这个贴到了 Vue 论坛。如果我找到解决方案,我会更新这两个问题!