headless-wp-starter icon indicating copy to clipboard operation
headless-wp-starter copied to clipboard

GraphQL: Navigating from page to page doesn't pull expected page content.

Open wrongakram opened this issue 5 years ago • 4 comments

Whenever I navigate from a page to another page it doesn't pull the "new" page content. Correct content is only generated when I go from a post to a page or home to a page. I will try to find a solution in the mean time.

wrongakram avatar Mar 01 '19 20:03 wrongakram

Hey @akramk22 , maybe this merged PR fixes your issue: https://github.com/postlight/headless-wp-starter/pull/198

alexiakl avatar Mar 02 '19 17:03 alexiakl

@alexiakl Updated the src folder to contain the changes. However still not having any luck. Page to Page fetching isn't updating for me :(

wrongakram avatar Mar 04 '19 15:03 wrongakram

Yep, I experience the same problem. Also, I found a bug in header-menu.php. A function that pulls menu items is based on menu name so if user change name of it in CMS, everything stops working. I made a small tweak and make it relay on location no menu name.

function get_items() {
  $counter    = 0;
  $locations = get_nav_menu_locations();
  $object = wp_get_nav_menu_object( $locations['header-menu'] );
  $menu_items = wp_get_nav_menu_items( $object->name );
  foreach ( $menu_items as $item ) {...}
}

DevOpsRadar avatar Mar 14 '19 22:03 DevOpsRadar

@akramk22 I found a solution to your menu problem: You need to add this to Post.js and a similar thing to Page.js:

componentDidUpdate(prevProps) {
  if (this.props.match.params.slug !== prevProps.match.params.slug) {
    this.executePostQuery();
  }
}

DevOpsRadar avatar Mar 15 '19 01:03 DevOpsRadar