Skip to content
Piyush Dankhra
Go back

Relation between custom URL Pattern and Component Path in PWA Studio

Last updated:

I assumed that you’re familiar with how to create an extension in the PWA Studio. If not, then I recommend you to check out the following resources:

In our custom extension, we can register and manage custom routes in the intercept.js file. For example:

module.exports = targets => {
    targets.of('@magento/venia-ui').routes.tap((routes) => {
        routes.push({
            name: 'Blogs',
            pattern: '/blog',
            path: '@dankhrapiyush/blog/lib/components/Blogs'
        });
        routes.push({
            name: 'Blog',
            pattern: '/blog/post/:id?',
            path: '@dankhrapiyush/blog/lib/components/Blog'
        });
        routes.push({
            name: 'BlogCategory',
            pattern: '/blog/category/:id?',
            path: '@dankhrapiyush/blog/lib/components/Category'
        });
        routes.push({
            name: 'BlogTag',
            pattern: '/blog/tag/:id?',
            path: '@dankhrapiyush/blog/lib/components/Tag'
        });
        return routes;
    });
}intercept.js

File source: github.com/dankhrapiyush/blog/blob/master/intercept.js

As we noticed in the code snippet, the route definition object has three parameters:

On the frontend, it matches the routes’ pattern in the bottom-to-top order and renders the component set in the path parameter.

Let’s say if the requested URL is:

I hope it clears the idea about how routes pattern and path co-relate to each other and how priority works.


Share this post on:

Previous Post
Override the component in the PWA Studio extension
Next Post
Thinking in PWA Studio extension development