Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consistent URLs that can contain trailing-slashes or not #4684

Closed
cewald opened this issue Jul 28, 2020 · 1 comment
Closed

Consistent URLs that can contain trailing-slashes or not #4684

cewald opened this issue Jul 28, 2020 · 1 comment
Labels
bug Bug reports VSF1 Issues in regards to VSF1
Milestone

Comments

@cewald
Copy link
Contributor

cewald commented Jul 28, 2020

Is there something you don't understand? What is it? Describe it.

If I wan't to force URL's to have a trailing slash it won't work for any dynamic routes. During the client-side router resolution the trailing slash will always be removed if the URL is a dynamic route which is resolved using url/mapUrl and url/mapFallbackUrl.

I can't explain this behavior to myself. If I set the desired URL as "static" route or even test it in a clean Vue sandbox-application it is working with a trailing slash either – but the in the VSF the beforeEach router guard and the RouterManager seems to cause this behavior. Is there an explanation for that?

Why is it useful?

If you switch a domain/website to the new PWA it might be necessary to stick to the existing URL structure. For example if you use GoogleAnalytics tracking which will report wrong metrics because the entry-points aren't the same as before when the / is removed. This might not be a common problem but can have a huge impact when your conversion-analytics-data relies on such details.

How to test?

For example:

  • Call a dynamic url like: https://www.sampleshop.com/de/sample-category/
    – in our example this url-path should target a route like { name: 'category', params: { slug: 'sample-category' }}
  • The desired category page should appear as planned
  • At the end of the client-side loading process the trailing slash disappears in the address bar

Unless you don't using the vue-router strict-mode you should be able to enter an URL using a / at the end or not. This is working so far – but on client-side rendering the slash disappears at the end.


I'm not even sure if this causes some relevant trouble for SEO but the (for me) unreasonable behavior is bothering me.
Any explanation and help is appreciated :)

@cewald cewald added the question If you are not sure how sth works or want discuss someting label Jul 28, 2020
@gibkigonzo
Copy link
Collaborator

In beforeEach we normalize path which removes trailing slash
const path = normalizeUrlPath(to.path)
then in processDynamicRoute/prepareDynamicRoute we replace path in route data with new without trailing slash.
We should change that. Maybe by using routeData.path instead of normalized path

@gibkigonzo gibkigonzo added bug Bug reports VSF1 Issues in regards to VSF1 and removed question If you are not sure how sth works or want discuss someting labels Jul 30, 2020
tdugue pushed a commit to tdugue/vue-storefront that referenced this issue Aug 10, 2020
following the opening of this issue (vuestorefront#4684) I created a configuration ( urlTrailingSlash ) to add or not the slash at the end of a url.

I changed the normalizeUrlPath function so that depending on the configuration the slash is added or not.

I also changed the prepareDynamicRoute function and added the pathToRegexpOptions attribute with the strict option following the slash config. pathToRegexpOptions tells the vuejs router not to remove the slash.
@gibkigonzo gibkigonzo added this to the 1.12.3 milestone Oct 2, 2020
@Fifciu Fifciu mentioned this issue Jan 5, 2021
6 tasks
@Fifciu Fifciu closed this as completed Jan 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug reports VSF1 Issues in regards to VSF1
Projects
None yet
Development

No branches or pull requests

3 participants