Volto - Registering new routes for nonContent Views

Hopefully this will save others from this newbie error when registering a view that is not for a content type (content type views are managed using config.views.contentTypesViews... in your src/config.js).

To ensure your custom routes are given priority over default routes, make sure that your route is registered BEFORE the addonRoutes and defaultRoutes.

Here's a snippet from a project I'm working on to register a new route for a component in Volto.
This code is added to the src/routes.js file of my Volto project, my route is /author/:author_id.

    path: '/',
    component: App, // Change this if you want a different component
    routes: [
      // Add your routes here
        path: '/author/:author_id',
        component: AuthorView,
        exact: true,
      ...(config.addonRoutes || []),

When I placed it AFTER the defaultRoutes, one of Volto's default routes got priority over mine specifically this one:

    path: '/**',
    component: View,

Once I relocated it to be BEFORE, my route started to resolve as expected.

Hope it helps someone (or my future self :slight_smile: ).

1 Like

Maybe the note from the original file that src/routes.js "replaces" would have helped: volto/routes.js at 46a121b9f90ef6f4257cd766aa6f7e7bdb509e5a · plone/volto · GitHub

That note was actually helpful when I was troubleshooting the issue.