Re: Question about locale-aware URLs

How to fix broken links with active locales on my website?

SchermerhornCO
Visitor
2 0 0

Hi all,

 

Storefront is huioneurope.com. There are no translations from English yet, but through Markets I have added different currencies. This created locales/subdirectories with '/en-xx'. 

 

As suggested by the documentation I have been using the routes object to generate URLs on the homepage. I thought I had it working but then I found out that the link would work when there was a locale, but wouldn't if you were visiting the primary domain.

 

I then changed one of the links from the routes objects to the shop_locale object but that breaks the link when a locale is active.

 

The attempts I made look like this:

 

 

1.
<a href="{{ shop_locale.root_url }}/products/{{ block.settings.psco_product1.handle }}">

2.
<a href="{{ routes.root_url }}/products/{{ block.settings.psco_product2.handle }}">

 

 

Am I missing something here? 

 

Thanks in advance for your time!

Replies 3 (3)

SchermerhornCO
Visitor
2 0 0

Problem solved.

MrSmileface
Shopify Partner
2 0 1

So how have you solved your problem?

StephenK
Shopify Partner
80 7 46

They may have solved it by switching to this syntax for links to collections:-

 

<a href="{{ products['handle'].url }}">Link</a>

 

I found this worked for me and wrote a blog post about it here.

You can use the same method with pages and collections if needed.

Some Shopify/Ecommerce related articles - https://medium.com/@stephenkeable