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 018812c

Browse files
authored
📝 Document integrating with Turbolinks when imported with Webpacker
[ci skip] resolves #899
1 parent 467cbd8 commit 018812c

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 によって変換されたページ (->オリジナル) /