vuejs / router

🚦 The official router for Vue.js

Home Page:https://router.vuejs.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow override of START_LOCATION

prodigy7 opened this issue · comments

What problem is this solving

Currently I'm using the storybook add-on storybook-vue3-router (https://github.com/NickMcBurney/storybook-vue3-router). As i have described, I've currently the problem, that simulating loading of page initial wouldn't work as expected, because vue-router initialize with / as start path (more details here NickMcBurney/storybook-vue3-router#58)

Proposed solution

I would recommend allowing the createRouter method to be given a URL that is entered instead of the current defaults (

export const START_LOCATION_NORMALIZED: RouteLocationNormalizedLoaded = {
). This way I hope that when simulating in Storybook I can directly initialise the URL exactly as needed.
In the end, I want to simulate as if a page were called up directly in the browser. This means, for example, that /app/product/1234 is entered directly instead of /app in the browser. At this point /app/product/1234 is then also picked up (perhaps in a different place than where I suggested).

Describe alternatives you've considered

To summarise, I somehow need the possibility to simulate the call of a given URL.

This functionality is not primarily required in production code but for simulation, e.g. in the Storybook add-on. The add-on sets currently the wished path as seen here: https://github.com/NickMcBurney/storybook-vue3-router/blob/19032cbe0029f531995b0d42222e72befc94c29a/src/utils.ts#L29

You can just await router.push('/initial') before initializing the view. Or if you’re within the browser and there is a global location object, await router.isReady()