Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

SilentImp
Copy link

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.

Copy link
Owner

@BDav24 BDav24 left a comment

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.

src/index.js Outdated
@@ -41,6 +41,7 @@ export default class UrlPrettifier<T: string> {
currentRoute.page === pageName)[0];
return {
href: `/${pageName}${this.paramsToQueryString(params)}`,
...(!route && {prefetch: false}),
Copy link
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)

Copy link
Author

@SilentImp SilentImp Feb 12, 2020

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
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
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
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 ;)

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