1 ---
2 sidebar_label: "no-trailing-slash-in-route-matcher"
3 ---
4
5 export const metadata = {
6 title: `no-trailing-slash-in-route-matcher - ESLint plugin rules`,
7 }
8
9 # {metadata.title}
10
11 This rule disallows route matchers passed to `defineMiddlewares` from ending with a trailing slash.
12
13 ## Severity
14
15 `warn`. This rule is enabled in the [recommended](../../page.mdx#recommended) preset.
16
17 ## What it Targets
18
19 This rule targets the `src/api/middlewares.ts` file. It reports a `matcher` string that ends with a trailing slash.
20
21 The following code is reported by the rule:
22
23 ```ts title="src/api/middlewares.ts"
24 export default defineMiddlewares({
25 routes: [
26 { matcher: "/store/custom/", middlewares: [] },
27 ],
28 })
29 ```
30
31 Instead, remove the trailing slash:
32
33 ```ts title="src/api/middlewares.ts"
34 export default defineMiddlewares({
35 routes: [
36 { matcher: "/store/custom", middlewares: [] },
37 ],
38 })
39 ```
40
41 ## Why it's Important
42
43 A matcher with a trailing slash doesn't match the same URLs as one without it, so the middleware may not run on the routes you expect. Removing the trailing slash keeps the matcher consistent with route paths.
44
45 Learn more in the [Middlewares documentation](!docs!/learn/fundamentals/api-routes/middlewares).
46
47 ## Fixable
48
49 This rule is auto-fixable. Run the linter with the `--fix` option to apply the fix automatically.
50
51 ## Turn it Off
52
53 To turn off this rule, set it to `off` in your ESLint configuration:
54
55 ```ts title="eslint.config.ts"
56 import { defineConfig } from "eslint/config"
57 import medusa from "@medusajs/eslint-plugin"
58
59 export default defineConfig([
60 ...medusa.configs.recommended,
61 {
62 rules: {
63 "@medusajs/no-trailing-slash-in-route-matcher": "off",
64 },
65 },
66 ])
67 ```
68
69 Or disable it for a single line using an inline comment:
70
71 ```ts
72 // eslint-disable-next-line @medusajs/no-trailing-slash-in-route-matcher
73 { matcher: "/store/custom/", middlewares: [] },
74 ```