From 6291b57f3a83c664173db36b844d6abd83fa2d96 Mon Sep 17 00:00:00 2001 From: JuanMa Garrido Date: Fri, 4 Oct 2024 11:23:05 +0100 Subject: [PATCH] working behaviour --- .../src/render.php | 3 --- .../interactivity-router-2f43f8/src/view.js | 19 ++++++------------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/plugins/interactivity-router-2f43f8/src/render.php b/plugins/interactivity-router-2f43f8/src/render.php index 80cf8ca3..2674dffc 100644 --- a/plugins/interactivity-router-2f43f8/src/render.php +++ b/plugins/interactivity-router-2f43f8/src/render.php @@ -16,7 +16,6 @@ data-wp-interactive="router-2f43f8" data-wp-router-region="region-example-2f43f8" - data-wp-init="callbacks.setUrlPathname" >

Displaying region "region-example-2f43f8" from

@@ -40,14 +39,12 @@
-

state.isPlayground:

block (region in display) attributes:

state.urlRegionDisplay:

-

state.urlRegionDisplaySlug:

diff --git a/plugins/interactivity-router-2f43f8/src/view.js b/plugins/interactivity-router-2f43f8/src/view.js index b2884101..e2c7d396 100644 --- a/plugins/interactivity-router-2f43f8/src/view.js +++ b/plugins/interactivity-router-2f43f8/src/view.js @@ -2,32 +2,25 @@ import { store } from '@wordpress/interactivity'; const { state } = store( 'router-2f43f8', { state: { - urlPathname: '', urlRegionDisplay: window.location.href, get urlRegionDisplaySlug() { - const isHome = state.urlPathname === '/'; + const { pathname } = new URL( state.urlRegionDisplay ); + const isHome = pathname === '/'; return isHome ? '/' - : '/' + state.urlPathname.split( '/' ).filter( Boolean ).pop(); - }, - get isPlayground() { - return state.urlPathname.includes( 'scope' ); - }, - }, - callbacks: { - setUrlPathname: () => { - state.urlPathname = new URL( state.urlRegionDisplay ).pathname; + : '/' + pathname.split( '/' ).filter( Boolean ).pop(); }, }, actions: { *navigate( e ) { - console.log( 'navigate', e ); e.preventDefault(); const { actions } = yield import( '@wordpress/interactivity-router' ); state.urlRegionDisplay = e.target.href; - yield actions.navigate( state.urlRegionDisplaySlug ); + + //yield actions.navigate( state.urlRegionDisplaySlug ); + yield actions.navigate( e.target.href ); }, }, } );