Convert Figma logo to code with AI

frontarm logonavi

🧭 Declarative, asynchronous routing for React.

2,068
71
2,068
43

Top Related Projects

29,083

Build Better Websites. Create modern, resilient user experiences with web fundamentals.

124,777

The React Framework

55,199

The best React-based framework with performance, scalability and security built in.

18,419

web development, streamlined

54,014

The Intuitive Vue Framework.

SolidStart, the Solid app framework

Quick Overview

Navi is a modern JavaScript router for single-page applications. It provides a declarative approach to routing, with built-in support for code splitting, server-side rendering, and static site generation. Navi aims to simplify the process of building complex, dynamic web applications with efficient navigation and content loading.

Pros

  • Declarative routing syntax for easier management of complex routes
  • Built-in support for code splitting and lazy loading
  • Seamless integration with React and static site generators
  • Supports server-side rendering and static site generation out of the box

Cons

  • Limited ecosystem compared to more established routing libraries
  • Steeper learning curve for developers accustomed to traditional routing approaches
  • Documentation could be more comprehensive for advanced use cases

Code Examples

  1. Basic route declaration:
import { mount, route } from 'navi';

const routes = mount({
  '/': route({
    view: <HomePage />
  }),
  '/about': route({
    view: <AboutPage />
  }),
  '/blog/:id': route(async req => ({
    view: <BlogPost id={req.params.id} />
  }))
});
  1. Lazy loading components:
import { lazy } from 'react';
import { mount, route } from 'navi';

const routes = mount({
  '/dashboard': route({
    view: lazy(() => import('./pages/Dashboard'))
  })
});
  1. Nested routes:
import { mount, route } from 'navi';

const routes = mount({
  '/': route({
    view: <Layout />,
    children: {
      '/': route({
        view: <HomePage />
      }),
      '/products': mount({
        '/': route({
          view: <ProductList />
        }),
        '/:id': route({
          view: <ProductDetails />
        })
      })
    }
  })
});

Getting Started

To start using Navi in your project:

  1. Install Navi and its React integration:
npm install navi react-navi
  1. Create your routes:
// routes.js
import { mount, route } from 'navi';
import { HomePage, AboutPage } from './pages';

export default mount({
  '/': route({
    view: <HomePage />
  }),
  '/about': route({
    view: <AboutPage />
  })
});
  1. Set up your app:
// App.js
import React from 'react';
import { Router, View } from 'react-navi';
import routes from './routes';

function App() {
  return (
    <Router routes={routes}>
      <View />
    </Router>
  );
}

export default App;

Competitor Comparisons

29,083

Build Better Websites. Create modern, resilient user experiences with web fundamentals.

Pros of Remix

  • Full-stack framework with server-side rendering and data loading
  • Built-in routing system with nested routes and layouts
  • Strong focus on web standards and progressive enhancement

Cons of Remix

  • Steeper learning curve due to its full-stack nature
  • Requires server-side infrastructure, which may increase complexity
  • Less flexible for purely client-side applications

Code Comparison

Remix route example:

export default function Index() {
  return <h1>Welcome to Remix</h1>;
}

export function loader() {
  return json({ message: "Hello from the server" });
}

Navi route example:

export default createPage({
  title: 'Welcome',
  content: <h1>Welcome to Navi</h1>,
  getData: async () => ({ message: "Hello from the server" })
})

Summary

Remix is a full-stack framework offering server-side rendering and data loading, while Navi is primarily a client-side routing library. Remix provides a more comprehensive solution for building web applications but requires more setup and infrastructure. Navi is simpler and more flexible for client-side routing needs but lacks built-in server-side capabilities. The choice between the two depends on the project requirements and the desired level of control over the application architecture.

124,777

The React Framework

Pros of Next.js

  • Larger ecosystem and community support
  • Built-in server-side rendering and static site generation
  • Extensive documentation and learning resources

Cons of Next.js

  • Steeper learning curve for beginners
  • More opinionated structure, which may limit flexibility
  • Heavier bundle size compared to Navi

Code Comparison

Next.js routing:

// pages/about.js
export default function About() {
  return <h1>About Page</h1>
}

Navi routing:

// routes.js
import { mount, route } from 'navi'

export default mount({
  '/about': route({
    view: <h1>About Page</h1>
  })
})

Both Next.js and Navi are React-based routing libraries, but they differ in their approach and features. Next.js offers a more comprehensive framework with built-in server-side rendering and static site generation, making it suitable for larger projects. It has a larger ecosystem and community support, which can be beneficial for developers seeking resources and third-party integrations.

On the other hand, Navi provides a lighter-weight solution with a focus on simplicity and flexibility. It has a gentler learning curve and allows for more customization in routing and application structure. Navi's bundle size is smaller, which can be advantageous for performance-critical applications.

The code comparison shows the difference in routing implementation between the two libraries. Next.js uses a file-based routing system, while Navi employs a more programmatic approach to defining routes.

55,199

The best React-based framework with performance, scalability and security built in.

Pros of Gatsby

  • Larger ecosystem with extensive plugins and themes
  • Built-in performance optimizations like image processing and code splitting
  • Strong community support and extensive documentation

Cons of Gatsby

  • Steeper learning curve, especially for developers new to React or GraphQL
  • Longer build times for large sites
  • More complex setup and configuration compared to simpler alternatives

Code Comparison

Navi:

import { createSwitch, createRoute } from 'navi';

const routes = createSwitch({
  '/': createRoute({ view: <HomePage /> }),
  '/about': createRoute({ view: <AboutPage /> }),
});

Gatsby:

import { createPages } from 'gatsby';

exports.createPages = async ({ actions }) => {
  const { createPage } = actions;
  createPage({
    path: '/',
    component: path.resolve(`./src/templates/home.js`),
  });
};

Summary

Gatsby is a more comprehensive static site generator with a rich ecosystem and powerful features, but it comes with increased complexity. Navi offers a simpler, more lightweight approach to routing and navigation in React applications. The choice between the two depends on project requirements, team expertise, and desired level of customization.

18,419

web development, streamlined

Pros of SvelteKit

  • Built-in server-side rendering and code-splitting for improved performance
  • Integrated with Svelte, offering a seamless full-stack development experience
  • Extensive ecosystem and community support

Cons of SvelteKit

  • Steeper learning curve for developers new to Svelte
  • Less flexibility in routing compared to Navi's declarative approach

Code Comparison

Navi routing:

<Routes>
  <Route path="/" view={<HomePage />} />
  <Route path="/about" view={<AboutPage />} />
</Routes>

SvelteKit routing:

// src/routes/+page.svelte
<h1>Home Page</h1>

// src/routes/about/+page.svelte
<h1>About Page</h1>

Key Differences

  • Navi focuses on declarative routing and navigation for React applications
  • SvelteKit is a full-featured framework for building Svelte applications
  • Navi offers more granular control over routing, while SvelteKit provides a more opinionated structure
  • SvelteKit includes built-in features like server-side rendering and API routes, which Navi doesn't provide out of the box

Both libraries have their strengths, with Navi excelling in flexible routing for React apps and SvelteKit offering a comprehensive solution for Svelte-based projects.

54,014

The Intuitive Vue Framework.

Pros of Nuxt

  • More comprehensive framework with built-in features like server-side rendering, static site generation, and automatic code splitting
  • Larger ecosystem and community support, with numerous plugins and modules available
  • Seamless integration with Vue.js, providing a smooth development experience for Vue developers

Cons of Nuxt

  • Steeper learning curve due to its more complex architecture and additional concepts
  • Potentially heavier bundle size for smaller projects that don't require all of Nuxt's features
  • Less flexibility in routing compared to Navi's declarative approach

Code Comparison

Navi routing:

<Routes>
  <Route path="/" view={<HomePage />} />
  <Route path="/about" view={<AboutPage />} />
</Routes>

Nuxt routing (file-based):

pages/
  index.vue
  about.vue

Summary

Nuxt is a more feature-rich framework built on top of Vue.js, offering a complete solution for building server-side rendered and static applications. It provides a structured approach to development with conventions and built-in optimizations. Navi, on the other hand, is a lightweight routing library that focuses on declarative routing and code-splitting, offering more flexibility but fewer out-of-the-box features. The choice between the two depends on project requirements, team expertise, and desired level of control over the application structure.

SolidStart, the Solid app framework

Pros of Solid Start

  • Built specifically for SolidJS, offering seamless integration and optimized performance
  • Provides a full-stack solution with server-side rendering (SSR) and API routes out of the box
  • Offers a more comprehensive framework with built-in features like file-based routing and meta management

Cons of Solid Start

  • Steeper learning curve due to its full-stack nature and SolidJS-specific concepts
  • Less flexible for use with other view libraries or frameworks
  • Still in beta, which may lead to potential instability or breaking changes

Code Comparison

Navi (Route Definition):

<Route path="/" view={<HomePage />} />
<Route path="/about" view={<AboutPage />} />

Solid Start (File-based Routing):

// pages/index.tsx
export default function Home() {
  return <h1>Home Page</h1>;
}

// pages/about.tsx
export default function About() {
  return <h1>About Page</h1>;
}

While Navi focuses on declarative routing with a more flexible approach, Solid Start leverages file-based routing, which can simplify the project structure but may be less customizable. Solid Start's integration with SolidJS and its full-stack capabilities make it a more comprehensive solution for SolidJS projects, whereas Navi offers greater flexibility for use with various view libraries.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Navi (unmaintained)

Unmaintained declarative, asynchronous routing for React.

NPM Build

Navi is an unmaintained JavaScript library for declaratively mapping URLs to asynchronous content.

It comes with:

  • A set of modern React components and hooks, with Suspense support
  • A static HTML generation tool that works with create-react-app without ejecting
  • Great TypeScript support

View the docs »

Quick Start

At it's core, Navi is just a router. You can use it with any React app – just add the navi and react-navi packages to your project:

npm install --save navi react-navi

If you'd like a more full featured starter, you can get started with Create React/Navi App:

npx create-react-navi-app my-app
cd my-app
npm start

Or if you want to create a blog, use create-react-blog:

npx create-react-blog react-blog
cd react-blog
npm start

Getting Started

For a full introduction, see the Getting Started guide on the Navi website.

Who's using Navi?

Contributing

We are grateful to the community for contributing bugfixes, documentation, translations, and any other improvements.

This repository is monorepo that holds the source for Navi and it's related packages, while the Navi website -- which includes Navi's documentation, is part of the navi-website repository.

Building and Testing Navi

To contribute code to Navi, you'll need to be able to build it and run the tests. To start, make sure you have lerna 3.x installed globally:

npm install -g lerna

Then fork, clone and bootstrap the repository:

lerna bootstrap
yarn build
yarn test

If you're working on Navi itself, it's often easier to run builds and tests from packages/navi

cd packages/navi
yarn test:watch

The examples are set up to use the copy of Navi at packages/navi/dist, so they can also be useful for quickly testing changes.

License

Navi is MIT licensed.

NPM DownloadsLast 30 Days