Skip to content

Turning off prefetch for pages that not in the routes list - #20

Open
SilentImp wants to merge 1 commit into
BDav24:masterfrom
SilentImp:master
Open

Turning off prefetch for pages that not in the routes list#20
SilentImp wants to merge 1 commit into
BDav24:masterfrom
SilentImp:master

Conversation

@SilentImp

Copy link
Copy Markdown

Hi.
Maybe it's a nice idea to turn off prefetch (which is default to true) if we don't have a page in the routes list?

Example: We are migrating site from monolith to next.js app. Now we have to manually set prefetch={false} to all links, that lead to the monolith or get 404 on prefetch attempt. But we will need to remove them after the migration is done. It would be nice to not crawl thru the project to fix all the links. And this way it can be done automatically.

With all best regards. Anton.

@BDav24 BDav24 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @SilentImp, yes good idea, thanks for your PR. I'd just make it as an option.

Comment thread src/index.js Outdated
currentRoute.page === pageName)[0];
return {
href: `/${pageName}${this.paramsToQueryString(params)}`,
...(!route && {prefetch: false}),

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not confortable with a lib changing default params for other libs, so we could pass it as an option, what do you think?
Something like:
new UrlPrettifier(routes, {preventPrefetchIfNoRoute: true}) (preventPrefetchIfNoRoute being false by default)

@SilentImp SilentImp Feb 12, 2020

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sound nice!
I will update an PR.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite like that you need to pass a property with such a long name, presumably each time you are using component … but I can't come with better naming, so I guess it's a good solution.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BDav24 updated PR :)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite like that you need to pass a property with such a long name, presumably each time you are using component …

Yes my first idea was to pass the param to the lib entrypoint new UrlPrettifier(routes, {preventPrefetchIfNoRoute: true}), so you don't have to pass it each time ;)

@SilentImp
SilentImp force-pushed the master branch 2 times, most recently from 98efda5 to d2d707c Compare February 12, 2020 14:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants