Documentation
Feedback
Guides
Learning Center

Learning Center
Learning Center
Navigation & Routes
View in Portuguese
This content was migrated from the VTEX Learning Center and is no longer being actively maintained. For the most accurate and up-to-date information, please check the official documentation.

Introduction

One of the highlights of a good admin application is to ensure that it is well-positioned and that navigation is simple. To control navigation in the VTEX admin side menu there are two files that will be useful: navigation.json androutes.json.

Navigation is the file that defines the navigation rules in the VTEX admin sidebar. With it, you can build from a simpler link, in which a click takes you to your app, how to build more complex menus with associated submenus.

{"base64":"  ","img":{"width":364,"height":574,"type":"png","mime":"image/png","wUnits":"px","hUnits":"px","length":35569,"url":"https://user-images.githubusercontent.com/60782333/107589617-28bba100-6be5-11eb-83d6-31486d1bafe3.png"}}

routes.json

The routes define the routes and associated react components, from your application, any component that is mapped to a route must be declared in the routes, even if it is not directly associated with a navigation item in navigation.json.

Atividade

  1. Within the /admin/folder created in the previous step, create two more files,navigation.json and routes.json:

_10
|_ admin/
_10
+ |_ navigation.json
_10
+ |_ routes.json

  1. In navigation.json create a JSON object with the properties section, titleId and path:

_10
{
_10
"section": "orders",
_10
"titleId": "admin-example.navigation.label",
_10
"path": "/admin/iotraining"
_10
}

  1. In routes.json assign a component and path to the created navigation:

_10
{
_10
"admin.app.example": {
_10
"component": "adminExample",
_10
"path": "/admin/app/iotraining"
_10
}
_10
}

NOTE: The mapping from a navigation to a route is done through the path. The path must diverge only by a /app/ in routes.json


_10
//navigation.json
_10
_10
/admin/{{yourpath}}
_10
_10
//routes.json
_10
_10
/admin/app/{{yourpath}}

  1. Finally, create a simple hello world component with the same name that you gave to component in routes.json:

_10
//react/adminExample.tsx
_10
import React, { FC } from 'react'
_10
_10
const AdminExample: FC = () => {
_10
return <h1>Hello, World!</h1>
_10
}
_10
_10
export default AdminExample

Link the application (vtex link). The result should be as follows:

{"base64":"  ","img":{"width":737,"height":374,"type":"png","mime":"image/png","wUnits":"px","hUnits":"px","length":23519,"url":"https://user-images.githubusercontent.com/18701182/92773790-486b4680-f373-11ea-8d1b-c4b84dad4375.png"}}

Notice that the created menu has no message yet, we will evolve it later, click on the blank space shown above to see the message of Hello, World!.

Answer sheet

See answer sheet for adminExample.tsx
adminExample.tsx

_10
import React, { FC } from 'react'
_10
_10
const AdminExample: FC = () => {
_10
return <h1>Hello, World!</h1>
_10
}
_10
_10
export default AdminExample

See answer sheet for navigation.json
navigation.json

_10
{
_10
"section": "orders",
_10
"titleId": "admin-example.navigation.label",
_10
"path": "/admin/iotraining"
_10
}

See answer sheet for routes.json
routes.json

_10
{
_10
"admin.app.example": {
_10
"component": "adminExample",
_10
"path": "/admin/app/iotraining"
_10
}
_10
}

On this page