DEV Community


Posted on

Why we may use relative path instead of fullpath in nextjs

Scenario : I have 2 levels of pages
page 1 which has page1.1 and page 1.2

Now, when these got blown to several pages you may end up with several pages and several sub pages. But, what happens to assets
will you change them to ../../assets for pages which are in deep levels and so forth

It can be resolved easily with something called reference path. what is reference path

A path with prepend slash will result in referencing of assets folder which is relative to root directory

Example instead of "../../assets/imgs" (fullPath) you can use "/assets/imgs" (relativePath) . Ofcourse, nextjs built this as in favor of root directory which will resolve in the beginning

So, always remember to use relative path so that it will resolve itself instead of fullPath

You can do a good read in fileSystementry about it

Top comments (0)