-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #127 from contember/scopes
add scopes
- Loading branch information
Showing
7 changed files
with
412 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
--- | ||
title: Routing and pages overview | ||
--- | ||
|
||
|
||
In order to define pages in Contember Interface, you need to export function components from files in the `admin/pages` directory (or its subdirectory). | ||
|
||
In the functions exported from page components, you will usually use one of the prepared [scope](./scopes.md) or [page](./pages-components) components provided by Contember. | ||
|
||
```typescript jsx | ||
export default () => { | ||
return ( | ||
<> | ||
<p>Page content here</p> | ||
</> | ||
) | ||
} | ||
``` | ||
|
||
## [Routing](./routing) | ||
|
||
Contember's routing system allows flexible structuring of your interface based on exported components from your files. You can create pages, subpages or nested pages based on your project's needs. This approach offers an intuitive way to design the navigation flow in your application. For more details, refer to the [routing section](./routing) in our documentation. | ||
|
||
## [Links and redirects](./links.md) | ||
|
||
In Contember, navigating through your application is made easy and intuitive through a range of dedicated components and hooks. These tools simplify the creation of hyperlinks, support static and dynamic parameters, and allow for programmable route changes based on your application's logic. This enables you to build a highly interactive and user-friendly interface, enhancing the overall user experience. For more specific information, please refer to the [links chapter](./links.md). | ||
|
||
## <span className="version">Interface 1.2+</span> [Scopes](./scopes) | ||
|
||
Contember provides several prepared scope components to help you quickly set up common pages in your admin panel. These scope components handle common tasks like loading and saving data, rendering form fields and displaying entity lists. | ||
|
||
## [Pages](./pages-components) | ||
|
||
While page components were once the standard for defining individual pages in Contember, they now represent a legacy approach. In new applications, we highly recommend utilizing [scopes](./scopes) for enhanced flexibility and efficiency. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
--- | ||
title: Routing | ||
--- | ||
|
||
Page names (and basically URL path) are constructed automatically. The resulting page name for the page will be determined by the file and function name, with slashes separating them. For example, the `default` export from a file named `post.tsx` will have the page name `post`, while a function exported as `edit` from a same file will be named `post/edit`. If a function is in a subdirectory, its path will also include the subdirectory name. For instance, a function named `edit` exported from | ||
`post/category.tsx` will have the name `post/category/edit`. | ||
|
||
## Routing options | ||
|
||
To define pages in Contember, you can use different exports. Each function exported from a page component defines a separate page. If you're looking for more advanced routing setups, understanding how to leverage different exports will be beneficial. | ||
|
||
### Default Export | ||
|
||
The `default` export is used to create the base page. It is given the name of the file. | ||
|
||
```typescript jsx | ||
export default () => { | ||
return ( | ||
<> | ||
<p>Post overview here</p> | ||
</> | ||
) | ||
} | ||
``` | ||
|
||
In the above example, if this was the `default` export from a file named `post.tsx`, the page name would be `post`. | ||
|
||
### Named Exports | ||
|
||
Named exports allow you to define subpages. The name of the function you export will be added to the URL path after a slash. For example: | ||
|
||
```typescript jsx | ||
export const Edit = () => { | ||
return ( | ||
<> | ||
<p>Edit post here</p> | ||
</> | ||
) | ||
} | ||
``` | ||
|
||
In this case, if the `Edit` function was exported from a file named `post.tsx`, the page name would be `post/edit`. | ||
|
||
### Exports from Subdirectories | ||
|
||
If your function is within a subdirectory, its path will also include the subdirectory name. This allows you to further nest your pages and organize your interface. For example, if you have a function named `Edit` exported from `post/category.tsx`, the page name would be `post/category/edit`. | ||
|
||
```typescript jsx | ||
export const Edit = () => { | ||
return ( | ||
<> | ||
<p>Edit post category here</p> | ||
</> | ||
) | ||
} | ||
``` | ||
|
||
### Multiple Named Exports from a Single File | ||
|
||
Building upon the routing options provided by Contember, you can define multiple pages from a single file using multiple named exports. | ||
|
||
Consider the following example from a file named `post.tsx`, where we're exporting two different components: `Create` and `Edit`. | ||
|
||
```typescript jsx | ||
// This is the Create Post page | ||
export const Create = () => { | ||
return ( | ||
<> | ||
<p>Here is where you can create a new post.</p> | ||
</> | ||
) | ||
} | ||
|
||
// This is the Edit Post page | ||
export const Edit = () => { | ||
return ( | ||
<> | ||
<p>Here is where you can edit an existing post.</p> | ||
</> | ||
) | ||
} | ||
``` | ||
|
||
With this setup, you're defining two new pages within your Contember interface: | ||
|
||
1. `post/create` - This page is rendered when the `Create` component is called. | ||
2. `post/edit` - This page is rendered when the `Edit` component is called. | ||
|
||
The names used for the exports, in this case, `Create` and `Edit`, will be reflected in the URL path for their respective pages. It's beneficial to use descriptive names as they give the user an understanding of the page's content or function. |
Oops, something went wrong.