GithubHelp home page GithubHelp logo

Slugs not working? about krabs HOT 1 OPEN

micheleriva avatar micheleriva commented on July 3, 2024
Slugs not working?

from krabs.

Comments (1)

KjellConnelly avatar KjellConnelly commented on July 3, 2024

I've played with it a little more. It's still not fully functional, but here's what I've learned so far...

If I want a slug to work, I have to use the actual page path. The way I've done it, at least for 1 site, is to edit next.config.js to add rewrites. This seems to work, but only for unique paths. IE: if I have a /blog directory in both website1 and website2, it won't work. I have to have something like /blog1 and /blog2. This is because SSG doesn't seem to handle the paths correctly. Well, here's what I've done:

Files

  • website1
    • index.js
    • blog
      • [slug].js
// website1/index.js
<Link href={`/blog/post-1`}>
   {`Link: docs/docs`}
</Link>
// next.config.js
const nextConfig = {
   ...
   async rewrites() {
    return [
         {
            source:'/blog/:slug',
            destination:'/website1/blog/:slug'
         }
      ]
   }
}

It looks like I'll need to do this for every single tenant... In nextConfig, source has to always be unique.

Any ideas on resolving this?

I can think of 2 solutions which are not ideal.

  1. Create my own system of generating blog post .js files and exporting them the correct directory before build. The problem with this is that I won't be able to use shared layouts. Each time I click a link, it will rerender the whole page. Each post will be wrapped in the same layout unfortunately. This is the reason I want slugs mainly.

  2. Have unique directories for ones with slugs in them. So if I have 10 tenants who run a blog, the url cannot be {website}/blog. Instead it'll have to be something like

  • {website}/myBlog,
  • {website}/jays-blog,
  • {website}/blogging,
  • {website}/blog,
  • {website}/blogger,
  • {website}/blogtastic,

This solution is ugly, and though I haven't thought through the implications of it, I'm willing to bet each tenant will have to have some sort of unique config file with certain keys, like the blogKey, or whatever. This is possible if I run all tenants. But if I have other people using them, I'll have to run certain checks to make sure keys aren't taken, or modify keys at build time when there are duplicate keys. Ugly ugly stuff.

from krabs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.