简体   繁体   中英

Call laravel naming routes from vue axios

Thinking is that any way to call the routes from route files with their names and get the url to axios in vuejs.

I don't know is it possible or not. If not please suggest me some other way to get the routes which i declared in laravel routes php files. Thanks

One solution would be to do a Route::getRoutesByName which will return all your routes keyed by the name you provided. You could create a route that returns that route collection.

See the API here: https://laravel.com/api/5.7/Illuminate/Routing/RouteCollection.html#method_getRoutesByName

    <script>
  window.routes = {
    'users' : '{{ route('users') }}',
    'contact' : '{{ route('contact') }}',
  }

  // You can access it like this
  let route = window.routes.users
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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