# 自定义路线

> Source: https://strapi.nodejs.cn/cms/backend-customization/examples/routes

🌐 Examples cookbook: Custom routes

自定义路由让你可以明确配置内容类型的路由，以控制身份验证并应用策略，例如绕过默认的 Strapi 身份验证或根据自定义条件限制访问。

🌐 Custom routes let you explicitly configure routes for content-types to control authentication and apply policies, such as bypassing default Strapi authentication or restricting access based on custom conditions.

:::callout 🏗 About these examples

这些示例是围绕 [FoodAdvisor](https://github.com/strapi/foodadvisor)构建的，而 [FoodAdvisor](https://github.com/strapi/foodadvisor)不再是Strapi的特色演示应用（它已被 [LaunchPad](https://github.com/strapi/LaunchPad)取代）。这里重要的是理解所展示的后端机制，而不是FoodAdvisor本身。这些页面将被重新访问以使用LaunchPad。

:::

:::prerequisites

此页面是后端自定义示例手册的一部分。请确保你已阅读其[介绍](/cms/backend-customization/examples)。

🌐 This page is part of the back end customization examples cookbook. Please ensure you've read its [introduction](/cms/backend-customization/examples).

:::

**💭 上下文:**

开箱即用时， [FoodAdvisor](https://github.com/strapi/foodadvisor)  不会控制对其内容类型端点的访问。

假设我们[之前创建了一个策略](/cms/backend-customization/examples/policies)来限制对“评论”内容类型的访问某些条件，例如防止餐厅老板为他们的餐厅创建评论。我们现在必须在用于创建评论的路由上启用该策略。

🌐 Let's say we [previously created a policy](/cms/backend-customization/examples/policies) to restrict access to the "Reviews" content-type to some conditions, for instance to prevent a restaurant's owner to create a review for their restaurants. We must now enable the policy on the route we use to create reviews.

**🎯 目标**:

- 明确定义“Reviews”内容类型的路由配置。
- 将创建评论时使用的路由配置为：
  - 绕过默认的 Strapi 身份验证系统
  - 并根据[先前定义的自定义策略](/cms/backend-customization/examples/policies)限制访问。

**相关概念**

更多信息可以在[政策](/cms/backend-customization/policies)和[路线](/cms/backend-customization/routes)文档中找到。

🌐 Additional information can be found in the [Policies](/cms/backend-customization/policies) and [Routes](/cms/backend-customization/routes) documentation.

**🧑‍💻 代码示例：**

在 [FoodAdvisor](https://github.com/strapi/foodadvisor) 项目的 `/api` 文件夹中，将 `api/src/api/review/routes/review.js` 文件的内容替换为以下代码：

```jsx title="src/api/review/routes/review.js"

'use strict';

const { createCoreRouter } = require('@strapi/strapi').factories;

module.exports = createCoreRouter('api::review.review', {
  config: {
    create: {
      auth: false, // set the route to bypass the normal Strapi authentication system
      policies: ['is-owner-review'], // set the route to use a custom policy
      middlewares: [],
    },
  },
});
```

<br />

:::strapi What's next?

了解更多关于如何配置[自定义中间件](/cms/backend-customization/examples/middlewares)以执行扩展你的 Strapi 应用的附加操作的信息。

🌐 Learn more about how to configure [custom middlewares](/cms/backend-customization/examples/middlewares) to perform additional actions that extend your Strapi-based application.

:::
