Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 83b6175

Browse files
Merge pull request #900 from mendelk/document-local-turbolinks
📝 Document integrating with Turbolinks when imported with Webpacker
2 parents 467cbd8 + 018812c commit 83b6175

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

‎README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,19 @@ ReactRailsUJS.detectEvents()
310310

311311
For example, if `Turbolinks` is loaded _after_ `ReactRailsUJS`, you'll need to call this again. This function removes previous handlers before adding new ones, so it's safe to call as often as needed.
312312

313+
If `Turbolinks` is `import`ed via Webpacker (and thus not available globally), `ReactRailsUJS` will be unable to locate it. To fix this, you can temporarily add it to the global namespace:
314+
315+
```js
316+
// Order is particular. First start Turbolinks:
317+
Turbolinks.start();
318+
// Add Turbolinks to the global namespace:
319+
window.Turbolinks = Turbolinks;
320+
// Remove previous event handlers and add new ones:
321+
ReactRailsUJS.detectEvents();
322+
// (Optional) Clean up global namespace:
323+
delete window.Turbolinks;
324+
```
325+
313326
### `getConstructor`
314327

315328
Components are loaded with `ReactRailsUJS.getConstructor(className)`. This function has two built-in implementations:

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /