我是 Vue.js 的新手并且正在作業,在更廣泛的軟體應用程式的背景關系中,前端使用 Vue.js,后端使用 Java。
用戶需要在同一個 Vue.js 應用的第一個運行實體和第二個運行實體之間重定向,才能申請保險合約。
Index.js 中的路由:
Vue.use(VueRouter);
const routes = [
{ path: "/", redirect: "/offer" },
{
path: "/offer",
component: SomeOffer,
children: [
{ path: "/", redirect: "generalInformation" },
{
path: "generalInformation",
name: "generalInformation",
component: GeneralInformation
},
{
path: "questions",
name: "Questions",
component: Questions
},
{
path: "insuredPerson",
name: "Insured Person",
component: InsuredPerson
},
{
path: "ourOffer",
name: "Our Offer",
component: OurOffer
},
{
path: "offermap",
name: "offermap",
component: OfferMapWrapper
}
]
},
{
path: "/registration",
component: Registration,
children: [
{ path: "/", redirect: "requester" },
{
path: "requester",
name: "requester",
component: Requester
},
{
path: "payment-provider",
name: "PaymentProvider",
component: PaymentProvider
},
{
path: "partnerdataInsuredPerson",
name: "Partner data Insured Person",
component: Partner data InsuredPerson
},
{
path: "healthquestions1",
name: "HealthQuestions 1",
component: HealthQuestions1
},
{
path: "healthquestions2",
name: "HealthQuestions2",
component: HealthQuestions2
},
{
path: "healthquestions3",
name: "HealthQuestions 3",
component: HealthQuestions3
},
{
path: "somepath",
name: "some path",
component: SomePath
},
{
path: "allowedPerson",
name: "allowded Person",
component: AllowdedPerson
},
{
path: "registeredperson",
name: "Registered Person",
component: RegisteredPerson
},
{
path: "initialdata",
name: "Initialdata",
component: InitialData
},
{
path: "protocoll",
name: "Protocoll",
component: Protocoll
},
{
path: "map",
name: "Map",
component: MapWrapper
},
{
path: "prints",
name: "Prints",
component: Prints
}
]
},
{
path: "/errors",
name: "Errors",
component: Errors
}
];
const router = new VueRouter({
base: process.env.ROUTER_BASE,
routes,
scrollBehavior() {
// https://router.vuejs.org/guide/advanced/scroll-behavior.html
return { x: 0, y: 0 };
}
});
router.afterEach(to => {
window.postMessage(
"merkeAktuelleSeite:" JSON.stringify({ aktuelleSeite: to.path }),
window.location.origin
);
});
export default router;
請注意 URL 中名為 warenkorbId 的變數-
初始網址:
http://xxx/yyy/zzz/plattformfrontend/insuranceapp?warenkorbId=b5a0b8e1-ad21-4c37-9a7e-84323c77fb29&produktId=33f4c5f0-36de-4b3a-be82-f6730582cdac&angebotId=ea3215b7-89/#58-72-4395-99注冊健康問題1
http://xxx/yyy/zzz/plattformfrontend/insuranceapp?warenkorbId=b5a0b8e1-ad21-4c37-9a7e-84323c77fb29&produktId=33f4c5f0-36de-4b3a-be82-f6730582cdac&angebotId=ea3215b7-89/#58-72-4395-99注冊健康問題2
等等。
When navigating to the other running Vue.js app instance, the URL looks like this:
http://xxx/yyy/zzz/plattformfrontend/insuranceapp?warenkorbId=b5a0b8e1-ad21-4c37-9a7e-84323c77fb29&produktId=33f4c5f0-36de-4b3a-be82-f6730582cdac&angebotId=ea3215b7-8872-4435-9950-5acfdd395b0c/#/registration/healthquestions2
but it should look like this:
http://xxx/yyy/zzz/plattformfrontend/insuranceapp?warenkorbId=b5a0b8e1-ad21-4c37-9a7e-84323c77fb29&produktId=33f4c5f0-36de-4b3a-be82-f6730582cdac&angebotId=ea3215b7-8872-4435-9950-5acfdd395b0c/#/registration/requester
So, basically, it should again navigate back to
/registration/requester (right)
but it navigates back again to
/registration/healthquestions2 (wrong)
How can I achieve that? Any hints or help would be very much appreciated, thanks!
uj5u.com熱心網友回復:
路由不是正確定義的路徑,您應該始終在 url 之前添加 / 或者對于重定向,您需要了解是否要直接重定向到組件,所以如果直接到任何不同的 url,這就是代碼。
對于直接組件
[{ path: '/home', redirect: { name: 'homepage' } }]
對于直接到 url
[{ path: '/home', redirect: '/' }]
這是檔案。
https://router.vuejs.org/guide/essentials/redirect-and-alias.html#redirect
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/455353.html
標籤:javascript vue.js routes vue-component vue-router
上一篇:Nuxtauth用戶始終為空
