Support the ongoing development of Laravel.io →
Breeze Laravel Vue.js

I am trying to have localized routes where the routes have the following pattern:

http://127.0.0.1:8000/en/about
http://127.0.0.1:8000/en/policy
http://127.0.0.1:8000/du/home

I am following this YT tutorial but when I try to access the app()->getLocale() I am getting the following error:

Error parsing JavaScript expression: Unexpected token

I found a workaround by passing locale variable to the vue component and then accepting it as a prop. But in this approach I have to repeat this for every route. Is there a way to use php variables inside .vue files or to pass a particular variable to each route in web.php file?

0
moderator

Hello @atif-bashir-1998 Where do you get the error?

The error you show looks like it is about javascript while the routing is part of Laravel.

0

This error is not regarding the route, it's basically a javascript problem. can you please show the javascript error?

Or you can set the locale in provider.

0

@tvbeek you are right this is a javascript error. I was trying to access the locale of the app. I was trying to use laravel's app->getLocale() inside vue component

tvbeek liked this reply

1

@skynet-technologies I have added the javascript error message here. I think the issue was because of my misunderstanding. I tried to use laravel's app->getLocale() inside vue component

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.