v3.0.0 to v4.0.0
To ensure a smooth migration from version 3.0.0 to 4.0.0, please follow these steps carefully. We recommend starting by comparing your package.json
file with the template’s package.json
file and updating all dependencies accordingly.
Middleware
In this release, we have removed the src/middleware.ts
file. Let us understand why we have done this.
We had written all the logic for Authentication and Translation in the src/middleware.ts
file. Next.js suggests to create a middleware file for both the logics (you may refer the same from here for Translation and here for Authentication) and we did exactly the same.
After doing this, we had deployed our demos on Vercel. After sometime we realized that on Vercel, there were too many Edge Middleware Invocations
. This was because the middleware was being invoked on every request. This was not the expected behavior. We further realized that many of our users might face the same issue and for no reason, they might have to pay more for the same.
So, we decided to remove the middleware and wrote all the logic in the respective HOCs. This way, the logic will only be invoked when the respective component is rendered. We have created three HOCs for the same and can be found in the src/hocs
folder. The HOCs are as follows:
AuthGuard
: This HOC will check if the user is authenticated or not. If the user is not authenticated, it will redirect the user to the login page. If you are visiting any protected route, you will be redirected to the login pageGuestOnlyRoute
: This HOC will check if the user is authenticated or not. If the user is authenticated, it will redirect the user to the dashboard page. If you are visiting any guest-only route (such as the login page), you will be redirected to the dashboard pageTranslationWrapper
: This HOC will check whether there is any language in the current URL. If not, it will redirect the user to the same URL with the default language.
Please refer here for migrating the Authentication and here for migrating the Translation.
We've made a couple of changes to how we handle the home page URL. The HOME_PAGE_URL
variable has been moved from the src/middleware.ts
file to the src/configs/themeConfig
.ts file and renamed to homePageUrl
. Additionally, the home page URL (/dashboards/crm
) is now also written in the next.config.mjs
file. If you need to update the home page URL, please remember to change it in both files.
Folder Structure Changes
We have made changes to the folder structure, including the introduction of public routes
, private routes
, and guest-only routes
, along with HOCs for user authorization. For instance, guest-only
routes are for pages like Login, Registration, and Forgot Password, accessible only to unauthenticated users.
For example, dashboard
pages are considered as private page which are accessible only to authenticated users. So we have moved the dashboard pages to the (private)
folder and Login
, Register
, Forgot Password
pages to the (guest-only)
folder. Front pages
are accessible to all users, so they are kept in the root folder which means public routes.
For more details, refer to this link so that you can bifurcate your routes accordingly.
Authentication
We have made changes to the authentication process, including the introduction of HOCs
and removed the middleware
file. To migrate:
-
Create
(private)
folder in the(dashboard)
folder and move all the content from thesrc/app/[lang]/(dashboard)
folder to thesrc/app/[lang]/(dashboard)/(private)
folder. -
Create
(guest-only)
folder in the(blank-layout-pages)
folder and move theLogin
,Register
, andForgot Password
pages to thesrc/app/[lang]/(blank-layout-pages)/(guest-only)
folder. -
Copy the following files from the template to your project:
src/hocs/AuthGuard.tsx
src/hocs/GuestOnlyRoute.tsx
src/components/AuthRedirect.tsx
src/app/[lang]/(blank-layout-pages)/(guest-only)/layout.tsx
-
Wrap your
src/app/[lang]/(dashboard)/(private)/layout.tsx
file with theAuthGuard
component as shown below:const Layout = async ({ children, params }: ChildrenType & { params: { lang: Locale } }) => {
return (
...
<AuthGuard>
<html {/* other props */}>
...
</html>
</AuthGuard>
...
)
}
export default Layout
You may refer to this link for more information on securing pages.
Translation (i18n)
We have removed the translation
logic from the middleware file as the src/middleware.ts
file has been removed from the template. To migrate:
-
Copy the
src/hocs/TranslationWrapper.tsx
andsrc/components/LangRedirect.tsx
files from the template to your project. -
Wrap your
src/app/[lang]/layout.tsx
file with theTranslationWrapper
component as shown below:const RootLayout = ({ children, params }: ChildrenType & { params: { lang: Locale } }) => {
return (
<TranslationWrapper {/* other props */}>
<html {/* other props */}>
...
</html>
</TranslationWrapper>
)
}
export default RootLayout
Search Library Update
In this update, we have replaced the kbar
search library with the cmdk search library because cmdk
provides timely package updates, whereas kbar
has not been updated for a long time and also console warnings appears. Since cmdk
is a completely new library, a direct upgrade is not possible.
Steps to Migrate:
-
Replace your
src/components/layout/shared/search
folder with the template'ssrc/components/layout/shared/search
folder. -
Replace your
src/data/searchData.ts
file with the template'ssrc/data/searchData.ts
file.
exactMatch and activeUrl
In this update, we have introduced the exactMatch
and activeUrl
props to make a menu item active based on the current dynamic URL. You may refer to this for verticalMenu and this for horizontalMenu.
Exclude Lang
In this update, we introduced the excludeLang
prop for greater flexibility in URL localization for dynamic menus and search. This prop allows you to exclude specific URLs from localization, making it easier to manage menu and search items that should not be translated.
Steps to Migrate:
-
For menuData files:
-
Locate your dynamic menu configuration file (
verticalMenuData.tsx
orhorizontalMenuData.tsx
) in thesrc/data/navigation
folder. -
Replace your
src/types/menuTypes.ts
file with the template'ssrc/types/menuTypes.ts
file. -
Add the
excludeLang : true
prop to the menu items that should not be localized.
We have added the
excludeLang
prop for thefront-pages
. You may refer to below example:{
label: dictionary['navigation'].landing,
href: '/front-pages/landing-page',
target: '_blank',
excludeLang: true
} -
-
For searchData file:
-
Locate
src/data/searchData.ts
file. -
Add
excludeLang?: boolean
in theSearchData
type. -
Add the
excludeLang
prop to the search items that should not be localized.
We have added the
excludeLang
prop for thefront-pages
. You may refer to below example:{
id: '1',
name: 'Landing Front',
url: '/front-pages/landing-page',
excludeLang: true,
icon: 'ri-article-line',
section: 'Front Pages'
} -
For detailed examples and more information on using excludeLang
, refer to the Vertical Menu and Horizontal Menu documentation.
Logo Component
In this update, we have removed the Link
component from the Logo
component. To migrate:
-
Replace your
src/components/layout/shared/Logo.tsx
file with thesrc/components/layout/shared/Logo.tsx
file from the template. -
Ensure that you remove any occurrences of the
component
prop associated with theLogo
component.
If you require the Logo
to function as a link, wrap it with the Link
component from next/Link
to achieve the desired redirection.
Other Changes
There might be some other changes that you need to make in your project. Please follow this guide for the same.