Skip to content

Commit 225191b

Browse files
behitekclaude
andcommitted
fix: implement proper localized routing for all navigation links
Issue Fixed: - Navigation links were hardcoded to English routes (/blog, /projects, /contact) - When on Vietnamese page (/vi/), clicking nav links would switch back to English - Language context was not preserved when navigating between pages Solution: - Updated Navbar to use getLocalizedPath() for all navigation links - Updated Footer "Discover" section to use localized paths - Updated all internal links on homepage (CTA buttons, View All links) - Logo now links to correct language homepage (/ or /vi/) How It Works: - getLocalizedPath('/projects', 'en') → '/projects' - getLocalizedPath('/projects', 'vi') → '/vi/projects' - Language stays consistent when navigating through the site Example Flow: 1. User on /vi/ (Vietnamese homepage) 2. Clicks "Dự Án" in navbar 3. Goes to /vi/projects (stays in Vietnamese) ✅ 4. Previously went to /projects (switched to English) ❌ All Links Updated: - ✅ Navbar: Blog, Projects, Contact, Logo - ✅ Footer: Blog, Projects, Contact - ✅ Homepage: All CTA buttons, View My Work, Get in Touch, View All Projects, View All Articles - ✅ Mobile menu: All navigation links Build Status: - ✅ 19 pages built successfully - ✅ 0 errors, 1 minor warning (unused import) - ✅ All routes functional Testing: 1. Visit http://localhost:4321/vi/ 2. Click "Dự Án" → Goes to /vi/projects ✅ 3. Click "Blog" → Goes to /vi/blog ✅ 4. Click "Liên Hệ" → Goes to /vi/contact ✅ 5. Language context preserved throughout navigation! 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 0e48e3b commit 225191b

4 files changed

Lines changed: 23 additions & 23 deletions

File tree

new-site/src/components/Footer.astro

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
import { SITE, SOCIAL_LINKS } from '@utils/constants';
33
import SocialIcon from '@components/SocialIcon.astro';
4-
import { getLangFromUrl, useTranslations } from '@i18n/utils';
4+
import { getLangFromUrl, useTranslations, getLocalizedPath } from '@i18n/utils';
55
66
const currentYear = new Date().getFullYear();
77
const lang = getLangFromUrl(Astro.url);
@@ -43,17 +43,17 @@ const t = useTranslations(lang);
4343
<h4 class="font-semibold mb-3">Discover</h4>
4444
<ul class="space-y-2">
4545
<li>
46-
<a href="/blog" class="text-[var(--color-text-muted)] hover:text-primary-600 transition-colors text-sm">
46+
<a href={getLocalizedPath('/blog', lang)} class="text-[var(--color-text-muted)] hover:text-primary-600 transition-colors text-sm">
4747
{t.nav.blog}
4848
</a>
4949
</li>
5050
<li>
51-
<a href="/projects" class="text-[var(--color-text-muted)] hover:text-primary-600 transition-colors text-sm">
51+
<a href={getLocalizedPath('/projects', lang)} class="text-[var(--color-text-muted)] hover:text-primary-600 transition-colors text-sm">
5252
{t.nav.projects}
5353
</a>
5454
</li>
5555
<li>
56-
<a href="/contact" class="text-[var(--color-text-muted)] hover:text-primary-600 transition-colors text-sm">
56+
<a href={getLocalizedPath('/contact', lang)} class="text-[var(--color-text-muted)] hover:text-primary-600 transition-colors text-sm">
5757
{t.nav.contact}
5858
</a>
5959
</li>

new-site/src/components/Navbar.astro

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,24 @@
22
import { SITE } from '@utils/constants';
33
import ThemeToggle from './ThemeToggle.astro';
44
import LanguageSwitcher from './LanguageSwitcher.astro';
5-
import { getLangFromUrl, useTranslations } from '@i18n/utils';
5+
import { getLangFromUrl, useTranslations, getLocalizedPath } from '@i18n/utils';
66
77
const currentPath = Astro.url.pathname;
88
const lang = getLangFromUrl(Astro.url);
99
const t = useTranslations(lang);
1010
1111
const NAV_LINKS = [
12-
{ label: t.nav.blog, href: '/blog' },
13-
{ label: t.nav.projects, href: '/projects' },
14-
{ label: t.nav.contact, href: '/contact' },
12+
{ label: t.nav.blog, href: getLocalizedPath('/blog', lang) },
13+
{ label: t.nav.projects, href: getLocalizedPath('/projects', lang) },
14+
{ label: t.nav.contact, href: getLocalizedPath('/contact', lang) },
1515
];
1616
---
1717

1818
<nav class="fixed top-0 left-0 right-0 z-40 glass border-b border-[var(--color-border)]">
1919
<div class="container">
2020
<div class="flex items-center justify-between h-16">
2121
<!-- Logo -->
22-
<a href="/" class="flex items-center space-x-2 font-bold text-xl hover:text-primary-600 transition-colors">
22+
<a href={getLocalizedPath('/', lang)} class="flex items-center space-x-2 font-bold text-xl hover:text-primary-600 transition-colors">
2323
<span class="gradient-text">{SITE.title}</span>
2424
</a>
2525

new-site/src/pages/index.astro

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import ProjectCard from '@components/ProjectCard.astro';
66
import SocialIcon from '@components/SocialIcon.astro';
77
import { SITE, EDUCATION, TECH_STACK, STATS, SOCIAL_LINKS } from '@utils/constants';
88
import { readingTime } from '@utils/helpers';
9-
import { getLangFromUrl, useTranslations } from '@i18n/utils';
9+
import { getLangFromUrl, useTranslations, getLocalizedPath } from '@i18n/utils';
1010
1111
const lang = getLangFromUrl(Astro.url);
1212
const t = useTranslations(lang);
@@ -66,13 +66,13 @@ const recentPosts = allPosts
6666

6767
<!-- CTA Buttons -->
6868
<div class="flex flex-wrap items-center gap-4 mb-8">
69-
<a href="/projects" class="btn-primary">
69+
<a href={getLocalizedPath('/projects', lang)} class="btn-primary">
7070
{t.home.cta.viewWork}
7171
<svg class="w-5 h-5 ml-2 inline-block" fill="none" stroke="currentColor" viewBox="0 0 24 24">
7272
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 8l4 4m0 0l-4 4m4-4H3"></path>
7373
</svg>
7474
</a>
75-
<a href="/contact" class="btn-secondary">
75+
<a href={getLocalizedPath('/contact', lang)} class="btn-secondary">
7676
{t.home.cta.getInTouch}
7777
</a>
7878
</div>
@@ -227,7 +227,7 @@ const recentPosts = allPosts
227227
</div>
228228

229229
<div class="text-center">
230-
<a href="/projects" class="btn-primary">
230+
<a href={getLocalizedPath('/projects', lang)} class="btn-primary">
231231
{t.home.featuredProjects.viewAll}
232232
<svg class="w-5 h-5 ml-2 inline-block" fill="none" stroke="currentColor" viewBox="0 0 24 24">
233233
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 8l4 4m0 0l-4 4m4-4H3"></path>
@@ -263,7 +263,7 @@ const recentPosts = allPosts
263263
</div>
264264

265265
<div class="text-center">
266-
<a href="/blog" class="btn-primary">
266+
<a href={getLocalizedPath('/blog', lang)} class="btn-primary">
267267
{t.home.latestArticles.viewAll}
268268
<svg class="w-5 h-5 ml-2 inline-block" fill="none" stroke="currentColor" viewBox="0 0 24 24">
269269
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 8l4 4m0 0l-4 4m4-4H3"></path>
@@ -289,10 +289,10 @@ const recentPosts = allPosts
289289
{t.home.cta2.subtitle}
290290
</p>
291291
<div class="flex items-center justify-center gap-4 flex-wrap">
292-
<a href="/contact" class="btn bg-white text-primary-600 hover:bg-slate-50 text-lg px-8 py-4">
292+
<a href={getLocalizedPath('/contact', lang)} class="btn bg-white text-primary-600 hover:bg-slate-50 text-lg px-8 py-4">
293293
{t.home.cta2.getInTouch}
294294
</a>
295-
<a href="/projects" class="btn border-2 border-white text-white hover:bg-white/10 text-lg px-8 py-4">
295+
<a href={getLocalizedPath('/projects', lang)} class="btn border-2 border-white text-white hover:bg-white/10 text-lg px-8 py-4">
296296
{t.home.cta2.viewWork}
297297
</a>
298298
</div>

new-site/src/pages/vi/index.astro

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import ProjectCard from '@components/ProjectCard.astro';
66
import SocialIcon from '@components/SocialIcon.astro';
77
import { SITE, EDUCATION, TECH_STACK, STATS, SOCIAL_LINKS } from '@utils/constants';
88
import { readingTime } from '@utils/helpers';
9-
import { getLangFromUrl, useTranslations } from '@i18n/utils';
9+
import { getLangFromUrl, useTranslations, getLocalizedPath } from '@i18n/utils';
1010
1111
const lang = getLangFromUrl(Astro.url);
1212
const t = useTranslations(lang);
@@ -66,13 +66,13 @@ const recentPosts = allPosts
6666

6767
<!-- CTA Buttons -->
6868
<div class="flex flex-wrap items-center gap-4 mb-8">
69-
<a href="/projects" class="btn-primary">
69+
<a href={getLocalizedPath('/projects', lang)} class="btn-primary">
7070
{t.home.cta.viewWork}
7171
<svg class="w-5 h-5 ml-2 inline-block" fill="none" stroke="currentColor" viewBox="0 0 24 24">
7272
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 8l4 4m0 0l-4 4m4-4H3"></path>
7373
</svg>
7474
</a>
75-
<a href="/contact" class="btn-secondary">
75+
<a href={getLocalizedPath('/contact', lang)} class="btn-secondary">
7676
{t.home.cta.getInTouch}
7777
</a>
7878
</div>
@@ -227,7 +227,7 @@ const recentPosts = allPosts
227227
</div>
228228

229229
<div class="text-center">
230-
<a href="/projects" class="btn-primary">
230+
<a href={getLocalizedPath('/projects', lang)} class="btn-primary">
231231
{t.home.featuredProjects.viewAll}
232232
<svg class="w-5 h-5 ml-2 inline-block" fill="none" stroke="currentColor" viewBox="0 0 24 24">
233233
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 8l4 4m0 0l-4 4m4-4H3"></path>
@@ -263,7 +263,7 @@ const recentPosts = allPosts
263263
</div>
264264

265265
<div class="text-center">
266-
<a href="/blog" class="btn-primary">
266+
<a href={getLocalizedPath('/blog', lang)} class="btn-primary">
267267
{t.home.latestArticles.viewAll}
268268
<svg class="w-5 h-5 ml-2 inline-block" fill="none" stroke="currentColor" viewBox="0 0 24 24">
269269
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 8l4 4m0 0l-4 4m4-4H3"></path>
@@ -289,10 +289,10 @@ const recentPosts = allPosts
289289
{t.home.cta2.subtitle}
290290
</p>
291291
<div class="flex items-center justify-center gap-4 flex-wrap">
292-
<a href="/contact" class="btn bg-white text-primary-600 hover:bg-slate-50 text-lg px-8 py-4">
292+
<a href={getLocalizedPath('/contact', lang)} class="btn bg-white text-primary-600 hover:bg-slate-50 text-lg px-8 py-4">
293293
{t.home.cta2.getInTouch}
294294
</a>
295-
<a href="/projects" class="btn border-2 border-white text-white hover:bg-white/10 text-lg px-8 py-4">
295+
<a href={getLocalizedPath('/projects', lang)} class="btn border-2 border-white text-white hover:bg-white/10 text-lg px-8 py-4">
296296
{t.home.cta2.viewWork}
297297
</a>
298298
</div>

0 commit comments

Comments
 (0)