-
Notifications
You must be signed in to change notification settings - Fork 63
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
feat: add new redirects feature #2583
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Skipped Deployment
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. |
Co-authored-by: Pedro Soares <32311264+pedromtec@users.noreply.github.com>
3ae0eaf
to
86ce7da
Compare
bedf1e0
to
017fc1f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🎉
Tested using the starter preview with the matcher and also tested the core adding enableRedirects true, it worked as expected!
} | ||
|
||
const response = await fetch( | ||
`https://${storeConfig.api.storeId}.myvtex.com/redirect-evaluate${pathname}` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to change this endpoint.
What's the purpose of this pull request?
The implementation of the redirects feature in FastStore appears as a strategic solution to facilitate the migration of old stores to our platform.
The idea of this feature is to run the redirect in the getStaticProps function when a certain page is not found. In other words, before rendering a not found (404) result to the user, we check if there is a redirect associated with the pathname requested by the user.
Since the pathname is not found (404). The redirect flow follows two steps. First it goes through a customization function called matcher. If the matcher cannot resolve the redirects, we validate whether a redirect exists in the rewriter database.
Components
Matcher: Optional function that can be implemented via customization. Some pathnames can be resolved via simple logic, without necessarily going to a database to check if there is a redirect registered. See an example.
Rewriter: If the redirect is not resolved via customization, a call will be made to the rewriter api to check if there is a redirect associated with the requested pathname.
Redirects RFC
How to test it?
https://storeframework.myvtex.com/admin/cms/redirects
We can run locally and try to access one of these redirects.
Example of matcher in starter: vtex-sites/starter.store#626
Example:
/produto/1