postlight / headless-wp-starter

🔪 WordPress + React Starter Kit: Spin up a WordPress-powered React app in one step
https://archive.postlight.com/labs/wordpress-react-starter-kit
GNU General Public License v2.0
4.48k stars 650 forks source link

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

Open wrongakram opened 5 years ago

wrongakram commented 5 years ago

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.

alexiakl commented 5 years ago

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

wrongakram commented 5 years ago

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

DevOpsRadar commented 5 years ago

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 commented 5 years ago

@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();
  }
}