<html lang="en">
<head></head>
<body>

<form id="mainForm" method="post" action="https://stackblitz.com/run" target="_self">
<input type="hidden" name="project[files][.gitignore]" value="node_modules
.DS_Store
dist
dist-ssr
*.local
">
<input type="hidden" name="project[files][README.md]" value="# TanStack Router - Framer Motion Integration Example

An example demonstrating integration with Framer Motion for animations.

- [TanStack Router Docs](https://tanstack.com/router)
- [Framer Motion Documentation](https://www.framer.com/motion/)

## Start a new project based on this example

To start a new project based on this example, run:

```sh
npx gitpick TanStack/router/tree/main/examples/react/with-framer-motion with-framer-motion
```

## Getting Started

Install dependencies:

```sh
pnpm install
```

Start the development server:

```sh
pnpm dev
```

## Build

Build for production:

```sh
pnpm build
```

## About This Example

This example demonstrates:

- Framer Motion integration
- Animated route transitions
- Page animations
- Gesture-based navigation
- Advanced animation patterns
">
<input type="hidden" name="project[files][index.html]" value="&lt;!doctype html&gt;
&lt;html lang=&quot;en&quot;&gt;
  &lt;head&gt;
    &lt;meta charset=&quot;UTF-8&quot; /&gt;
    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot; /&gt;
    &lt;title&gt;Vite App&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;div id=&quot;app&quot;&gt;&lt;/div&gt;
    &lt;script type=&quot;module&quot; src=&quot;/src/main.tsx&quot;&gt;&lt;/script&gt;
  &lt;/body&gt;
&lt;/html&gt;
">
<input type="hidden" name="project[files][package.json]" value="{&quot;name&quot;:&quot;tanstack-router-react-example-with-framer-motion&quot;,&quot;private&quot;:true,&quot;type&quot;:&quot;module&quot;,&quot;scripts&quot;:{&quot;dev&quot;:&quot;vite --port 3000&quot;,&quot;build&quot;:&quot;vite build &amp;&amp; tsc --noEmit&quot;,&quot;preview&quot;:&quot;vite preview&quot;,&quot;start&quot;:&quot;vite&quot;},&quot;dependencies&quot;:{&quot;@tailwindcss/vite&quot;:&quot;^4.1.18&quot;,&quot;@tanstack/react-router&quot;:&quot;https://pkg.pr.new/TanStack/router/@tanstack/react-router@e1c34ffdf31d70311e79f524a1c35a5fa644ea03&quot;,&quot;@tanstack/react-router-devtools&quot;:&quot;https://pkg.pr.new/TanStack/router/@tanstack/react-router-devtools@e1c34ffdf31d70311e79f524a1c35a5fa644ea03&quot;,&quot;framer-motion&quot;:&quot;^11.18.2&quot;,&quot;react&quot;:&quot;^19.0.0&quot;,&quot;react-dom&quot;:&quot;^19.0.0&quot;,&quot;redaxios&quot;:&quot;^0.5.1&quot;,&quot;tailwindcss&quot;:&quot;^4.1.18&quot;,&quot;zod&quot;:&quot;^3.24.2&quot;},&quot;devDependencies&quot;:{&quot;@types/react&quot;:&quot;^19.0.8&quot;,&quot;@types/react-dom&quot;:&quot;^19.0.3&quot;,&quot;@vitejs/plugin-react&quot;:&quot;^4.3.4&quot;,&quot;typescript&quot;:&quot;^5.7.2&quot;,&quot;vite&quot;:&quot;^7.3.1&quot;}}">
<input type="hidden" name="project[files][tsconfig.json]" value="{
  &quot;compilerOptions&quot;: {
    &quot;strict&quot;: true,
    &quot;esModuleInterop&quot;: true,
    &quot;jsx&quot;: &quot;react-jsx&quot;,
    &quot;skipLibCheck&quot;: true,
    &quot;lib&quot;: [&quot;DOM&quot;, &quot;DOM.Iterable&quot;, &quot;ES2022&quot;]
  }
}
">
<input type="hidden" name="project[files][vite.config.js]" value="import { defineConfig } from &#39;vite&#39;
import react from &#39;@vitejs/plugin-react&#39;
import tailwindcss from &#39;@tailwindcss/vite&#39;

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [tailwindcss(), react()],
})
">
<input type="hidden" name="project[files][.vscode/settings.json]" value="{
  &quot;files.watcherExclude&quot;: {
    &quot;**/routeTree.gen.ts&quot;: true
  },
  &quot;search.exclude&quot;: {
    &quot;**/routeTree.gen.ts&quot;: true
  },
  &quot;files.readonlyInclude&quot;: {
    &quot;**/routeTree.gen.ts&quot;: true
  }
}
">
<input type="hidden" name="project[files][src/main.tsx]" value="import * as React from &#39;react&#39;
import * as ReactDOM from &#39;react-dom/client&#39;
import { AnimatePresence, motion } from &#39;framer-motion&#39;
import {
  ErrorComponent,
  Link,
  Outlet,
  RouterProvider,
  createRootRoute,
  createRoute,
  createRouter,
  useMatch,
  useMatches,
} from &#39;@tanstack/react-router&#39;
import { TanStackRouterDevtools } from &#39;@tanstack/react-router-devtools&#39;
import axios from &#39;redaxios&#39;
import &#39;./styles.css&#39;

type PostType = {
  id: string
  title: string
  body: string
}

const fetchPosts = async () =&gt; {
  console.info(&#39;Fetching posts...&#39;)
  await new Promise((r) =&gt; setTimeout(r, 500))
  return axios
    .get&lt;Array&lt;PostType&gt;&gt;(&#39;https://jsonplaceholder.typicode.com/posts&#39;)
    .then((r) =&gt; r.data.slice(0, 10))
}

const fetchPost = async (postId: string) =&gt; {
  console.info(`Fetching post with id ${postId}...`)
  await new Promise((r) =&gt; setTimeout(r, 500))
  const post = await axios
    .get&lt;PostType&gt;(`https://jsonplaceholder.typicode.com/posts/${postId}`)
    .then((r) =&gt; r.data)

  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
  if (!post) {
    throw new NotFoundError(`Post with id &quot;${postId}&quot; not found!`)
  }

  return post
}

export const mainTransitionProps = {
  initial: { y: -20, opacity: 0, position: &#39;absolute&#39; },
  animate: { y: 0, opacity: 1, damping: 5 },
  exit: { y: 60, opacity: 0 },
  transition: {
    type: &#39;spring&#39;,
    stiffness: 150,
    damping: 10,
  },
} as const

export const postTransitionProps = {
  initial: { y: -20, opacity: 0 },
  animate: { y: 0, opacity: 1, damping: 5 },
  exit: { y: 60, opacity: 0 },
  transition: {
    type: &#39;spring&#39;,
    stiffness: 150,
    damping: 10,
  },
} as const

const rootRoute = createRootRoute({
  component: () =&gt; {
    const matches = useMatches()
    const match = useMatch({ strict: false })
    const nextMatchIndex = matches.findIndex((d) =&gt; d.id === match.id) + 1
    const nextMatch = matches[nextMatchIndex]

    return (
      &lt;&gt;
        &lt;div className=&quot;p-2 flex gap-2 text-lg&quot;&gt;
          &lt;Link
            to=&quot;/&quot;
            activeProps={{
              className: &#39;font-bold&#39;,
            }}
            activeOptions={{ exact: true }}
          &gt;
            Home
          &lt;/Link&gt;{&#39; &#39;}
          &lt;Link
            to=&quot;/posts&quot;
            activeProps={{
              className: &#39;font-bold&#39;,
            }}
          &gt;
            Posts
          &lt;/Link&gt;
        &lt;/div&gt;
        &lt;hr /&gt;
        &lt;AnimatePresence mode=&quot;wait&quot;&gt;
          &lt;Outlet key={nextMatch.id} /&gt;
        &lt;/AnimatePresence&gt;
        {/* Start rendering router matches */}
        &lt;TanStackRouterDevtools position=&quot;bottom-right&quot; /&gt;
      &lt;/&gt;
    )
  },
})

const indexRoute = createRoute({
  getParentRoute: () =&gt; rootRoute,
  path: &#39;/&#39;,
  component: () =&gt; {
    return (
      &lt;motion.div className=&quot;p-2&quot; {...mainTransitionProps}&gt;
        &lt;h3&gt;Welcome Home!&lt;/h3&gt;
      &lt;/motion.div&gt;
    )
  },
})

const postsLayoutRoute = createRoute({
  getParentRoute: () =&gt; rootRoute,
  path: &#39;posts&#39;,
  loader: () =&gt; fetchPosts(),
  component: () =&gt; {
    const posts = postsLayoutRoute.useLoaderData()
    return (
      &lt;motion.div className=&quot;p-2 flex gap-2&quot; {...mainTransitionProps}&gt;
        &lt;ul className=&quot;list-disc pl-4&quot;&gt;
          {[...posts, { id: &#39;i-do-not-exist&#39;, title: &#39;Non-existent Post&#39; }].map(
            (post) =&gt; {
              return (
                &lt;li key={post.id} className=&quot;whitespace-nowrap&quot;&gt;
                  &lt;Link
                    to={postRoute.to}
                    params={{
                      postId: post.id,
                    }}
                    className=&quot;block py-1 text-blue-800 hover:text-blue-600&quot;
                    activeProps={{ className: &#39;text-black font-bold&#39; }}
                  &gt;
                    &lt;div&gt;{post.title.substring(0, 20)}&lt;/div&gt;
                  &lt;/Link&gt;
                &lt;/li&gt;
              )
            },
          )}
        &lt;/ul&gt;
        &lt;hr /&gt;
        &lt;AnimatePresence&gt;
          &lt;Outlet /&gt;
        &lt;/AnimatePresence&gt;
      &lt;/motion.div&gt;
    )
  },
})

const postsIndexRoute = createRoute({
  getParentRoute: () =&gt; postsLayoutRoute,
  path: &#39;/&#39;,
  component: () =&gt; &lt;div&gt;Select a post.&lt;/div&gt;,
})

class NotFoundError extends Error {}

const postRoute = createRoute({
  getParentRoute: () =&gt; postsLayoutRoute,
  path: &#39;$postId&#39;,
  loader: ({ params: { postId } }) =&gt; fetchPost(postId),
  errorComponent: ErrorComponent,
  component: () =&gt; {
    const post = postRoute.useLoaderData()
    return (
      &lt;motion.div className=&quot;space-y-2&quot; {...postTransitionProps}&gt;
        &lt;h4 className=&quot;text-xl font-bold underline&quot;&gt;{post.title}&lt;/h4&gt;
        &lt;div className=&quot;text-sm&quot;&gt;{post.body}&lt;/div&gt;
      &lt;/motion.div&gt;
    )
  },
})

const routeTree = rootRoute.addChildren([
  postsLayoutRoute.addChildren([postRoute, postsIndexRoute]),
  indexRoute,
])

// Set up a Router instance
const router = createRouter({
  routeTree,
  defaultPreload: &#39;intent&#39;,
  scrollRestoration: true,
  context: {
    // loaderClient,
  },
})

// Register things for typesafety
declare module &#39;@tanstack/react-router&#39; {
  interface Register {
    router: typeof router
  }
}

const rootElement = document.getElementById(&#39;app&#39;)!

if (!rootElement.innerHTML) {
  const root = ReactDOM.createRoot(rootElement)

  root.render(
    &lt;React.StrictMode&gt;
      &lt;RouterProvider router={router} /&gt;
    &lt;/React.StrictMode&gt;,
  )
}
">
<input type="hidden" name="project[files][src/styles.css]" value="@import &#39;tailwindcss&#39; source(&#39;../&#39;);

@layer base {
  *,
  ::after,
  ::before,
  ::backdrop,
  ::file-selector-button {
    border-color: var(--color-gray-200, currentcolor);
  }
}

html {
  color-scheme: light dark;
}
* {
  @apply border-gray-200 dark:border-gray-800;
}
body {
  @apply bg-gray-50 text-gray-950 dark:bg-gray-900 dark:text-gray-200;
}
">
<input type="hidden" name="project[description]" value="generated by https://pkg.pr.new">
<input type="hidden" name="project[template]" value="node">
<input type="hidden" name="project[title]" value="tanstack-router-react-example-with-framer-motion">
</form>
<script>document.getElementById("mainForm").submit();</script>

</body></html>