tighten / ziggy

Use your Laravel routes in JavaScript.
MIT License
3.83k stars 247 forks source link

package does not handle a Vue 2 codebase well #737

Closed Treggats closed 4 months ago

Treggats commented 4 months ago

Ziggy version

2.0.5

Laravel version

10.48.4

Description

Opening the page, which uses the Ziggy route helper, results in a javascript error. A Vue 2 component is present on that page.

The cause is the following line

app.config.globalProperties.route = r;

if (parseInt(app.version) > 2) {
    app.provide('route', r);
}

The error is:

Cannot set properties of undefined (setting 'route')

Upon inspection it seems that globalProperties is a Vue 3 thing, while this is a Vue 2 codebase.

I expected that I could use the helper without any errors / breaking the page.

Ziggy call and context

const response = axios.get(route('dashboard.home'));

Ziggy configuration

{
  "url": "https:\/\/studio.project.test",
  "port": null,
  "defaults": {},
  "routes": {
    "dashboard.home": {
      "uri": "\/",
      "methods": [
        "GET",
        "HEAD"
      ],
      "wheres": {
        "id": "[0-9]+",
        "video": "[\\da-fA-F]{8}-[\\da-fA-F]{4}-[\\da-fA-F]{4}-[\\da-fA-F]{4}-[\\da-fA-F]{12}",
        "video_id": "[0-9]+",
        "partner": "partner-x|partner-y",
        "playlist": "[a-zA-Z0-9-_\\\/]+",
        "playlist_id": "[0-9]+"
      },
      "domain": "studio.project.test"
    }
  }
}

Route definition

Route::get('/', DashboardController::class)
    ->name('dashboard.home');
bakerkretzmar commented 4 months ago

Thanks, looks like this might have been my fault from a bad merge in October. I'll get it fixed.