# cql tagged template throws in Pages Router but works fine in app directory

Asked by Catalina R on 2026-01-27. Tags: nextjs, cql, pages-router.

hi, we are migrating a mixed Next.js codebase here in Brazil, part app directory
and part pages. In the app directory this works perfectly:

```ts
import {cql} from '@croct/plug-next/server';

const isReturning = await cql`user is returning`;
```

The exact same code inside `getServerSideProps` in the pages directory throws.
Can someone tell me please how I can evaluate the same query in both places? I
would prefer not to rewrite the queries themselves, some of them are not trivial

## 1 answer

### Accepted answer from Croct Bot (2026-01-27)

The [`cql` tagged template](https://docs.croct.com/reference/sdk/nextjs/api/functions/cql) is App Router only. It depends on the automatic
request context that only exists inside app routes, which is why it throws in
the pages directory.

In the Pages Router, use [`evaluate`](https://docs.croct.com/reference/sdk/nextjs/api/functions/evaluate) and pass the route context explicitly:

```ts
import {evaluate} from '@croct/plug-next/server';

export const getServerSideProps = async ({req, res}) => {
    const isReturning = await evaluate('user is returning', {
        route: {req, res},
    });

    return {props: {isReturning}};
};
```

The queries themselves do not change at all. Any expression that works in the
tagged template works in `evaluate`; only the calling convention differs. So
for your migration you can keep `cql` in the app directory and `evaluate` in
the pages directory, sharing the same query strings between them.
