简体   繁体   English

在Twig模板中使用正确的href路径

[英]Using the correct href path in a Twig template

I have this link in my Twig template: 我的Twig模板中有以下链接:

<li><a href="categories/{{ category.id }}">{{ category.category }}</a></li>

On the first page load, it loads as expected. 在首页加载时,它按预期加载。 For example: 例如:

<li><a href="categories/10">Music</a></li>

When I click on this link, it keep adding this to the url. 当我单击此链接时,它会继续将其添加到URL中。 For example, if I clicked on it 3 times, I get: 例如,如果我单击3次,则得到:

http://localhost:8080/myApp/categories/categories/categories/10

How can I get the correct path instead of just keeping adding to it? 如何获得正确的路径,而不仅仅是不断添加? Is this a Twig parameter I should be using? 这是我应该使用的Twig参数吗?

I think it's because you have given relative URI instead of absolute one. 我认为这是因为您给出的是相对URI,而不是绝对的URI。

try giving your base URI before categories 尝试在类别之前给出您的基本URI

<li><a href="{{ YOUR_BASE_URI }}/categories/{{ category.id }}"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM