react-snap icon indicating copy to clipboard operation
react-snap copied to clipboard

Only pre renders home or landing page but not other routes?

Open kaloraat opened this issue 4 years ago • 12 comments

Bug Report

Current Behavior It Only pre renders home/main or landing page not other routes. I am using react-router-dom.

Reproducible demo https://priceless-curran-c32657.netlify.app/about I have deployed to netlify. you can try on this on /about page. If you click view page source and search for "This is about". It is not found.

However it works on home page, you can click view page source and search for text "Give it a title" or "Write your story" it is found.

This issue was also asked on stack overflow.

kaloraat avatar Jun 29 '20 01:06 kaloraat

Actually react-snap scan links like this <Link to="/about/">about</Link>, not the declared routes, add links that match a route for other pages and test.

mohcinenazrhan avatar Jul 04 '20 16:07 mohcinenazrhan

@mohcinenazrhan sorry I didn't understand.. I have two page in my app. One is pre-rendered, other is not. I want to know why its happening and the possible solution. It's just a simple react app using react-router-dom? Is there something special needs to be done?? I have no idea what you are talking about declared routes, add links that match a route for other pages??

kaloraat avatar Jul 05 '20 03:07 kaloraat

@kaloraat does your app have a link component like this <Link to="/page/">page</Link> for the page that is not pre-rendered?

mohcinenazrhan avatar Jul 11 '20 20:07 mohcinenazrhan

Has anyone found solution for this problem? I am having exactly same problem and its only prerender home page not other routes.

kzatin avatar Oct 08 '20 06:10 kzatin

Like @mohcinenazrhan said react-snap only crawls pages it finds with <Link to="/about">About</Link>. If you don't have a link it won't crawl the page.

joshbedo avatar Dec 06 '20 21:12 joshbedo

it should crawl all links declared on the page, I have had no issues.. you may try the forked version of react-snap which I belive allows you to declare which routes to include or exclude.

ricky11 avatar May 02 '21 05:05 ricky11

I want to do exactly the opposite. Can I pre-render just one single route? for example. ignore index.html but prerender about.html

maxmedina05 avatar Apr 20 '22 15:04 maxmedina05

@mohcinenazrhan Where do I declare those Link tags?

zaykhere avatar Sep 01 '22 09:09 zaykhere

I am having this problem too. It also puts the main page code on other pages. I guess I need to make my program for that.

SiimTulev avatar Sep 06 '22 14:09 SiimTulev

Does anybody resolved this issue ??

komxvl avatar Nov 24 '22 10:11 komxvl

I had the same issue and found the solution for me! It didn't pick up pages linked in the navigation. I added the links on the main page, now it picked them up :)

atjpatatatj2 avatar Jul 17 '23 17:07 atjpatatatj2

Workaround Solution Found

I encountered the same issue with react-snap, and I managed to find a workaround solution that might be helpful to others facing similar problems. The issue seems to be related to certain components causing problems during pre-rendering.

I've implemented the following code snippet in my project, and it has successfully resolved the issue for me:

const Component = () => {
  // Check if the user agent is ReactSnap
  const isSnap = navigator.userAgent === 'ReactSnap';

  return (
    <div className="main">
      <>
        { !isSnap && <ComponentToKeepDynamic /> }
      </>
    </div>
  );
};

export default Component;

This code allows you to conditionally render components based on whether the user agent is ReactSnap or not. It effectively avoids rendering certain elements during the pre-rendering process, which can be particularly useful when dealing with components causing react-snap issues.

I hope this workaround proves helpful to others facing a similar situation. Please let me know if you have any questions or need further assistance!

Abderrahmenla avatar Sep 12 '23 02:09 Abderrahmenla