Vue spa template urls

Using the Vue spa template, I’m getting for routes that are not protected you can copy and paste a url into the address bar and the url is unchanged after the page loads .e.g.

Entering https://localhost:5173/counter?id=1

Doing the same on a protected route the query disappears

Entering https://localhost:5173/bookings-auto?id=1

Not sure if this is by design or an oversight?

Thanks

You should be able to change your App’s routing behaviour in its routing.ts

Thanks for that, just interested in the why it is like that, I don’t want to hack at something fundamental like that for the template solution and shoot myself in the foot later on.

The routing behavior is implemented by vue-router and configured in your App’s routing.ts. We don’t have control over or support 3rd party JS libs.

Its not my template and it doesn’t look like it was to do with vue-router either. There isn’t enough history in your repo to see how it got there.

Modifying the code from the vue-spa template

to

    const invalidAttrRedirect = (to: RouteLocationNormalized, guardAttr: string, userAttrs: string[]) => userAttrs.indexOf('auth') === -1
        ? Routes.signin(to.fullPath)
        : Routes.forbidden()

Preserves the query strings when the user refreshes the page or manually enter the url. Hope it saves someone time figuring it out in the future.

1 Like