denoland / fresh

The next-gen web framework.
https://fresh.deno.dev
MIT License
12.53k stars 648 forks source link

Plugin routes should be able to change the route config #2352

Open epangelias opened 8 months ago

epangelias commented 8 months ago

Routes in a plugin should allow configuring the route configuration options. This would allow plugins to add pages without the app's layout or app wrapper to effect it. This would allow easier integration of plugins without need to do any changes to layout or app wrappers on the app.

An example of this is in the KV Insights plugin, additional configuration must be done on any layout wrappers. The plugin provides the following code as a work-around:

// routes/_app.tsx

import { AppProps } from '$fresh/server.ts';

export default function App(props: AppProps) {
  if (context.url.pathname.startsWith('/kv-insights/')) {
    return <props.Component />;
  }

  return (
    <div class='wrapper'>
      <props.Component />
    </div>
  );
}

This is how this feature could be implemented:

export default {
  name: 'plugin',
  routes: [
      {
          path: '/admin',
          handler: handler,
          component: component,
                  config: { skipInheritedLayouts: true },
      },
  ],
} as Plugin
deer commented 8 months ago

duplicate of #2296