How to implement SEO-friendly Library URLs in JohnCMS without breaking routing

1
.

Hello everyone,
I’m working on the Library module in JohnCMS and trying to implement SEO-friendly URLs, but I’m running into routing conflicts and some runtime issues.
I would appreciate guidance from anyone who has implemented a similar setup cleanly.
🎯 Target URL structure
I want the Library module to support the following URLs:

/library/
/library/1
/library/1/testing-seo

Instead of:

/library?id=1

❗ Current issues
After implementing custom routing, I’m facing these problems:
1. Route conflict
/library/1 works correctly
/library/1/testing-seo returns 404
/library/ sometimes returns 404 depending on route order
2. Navigation error
Occasionally I get:

NavChain::add(): Argument #1 ($name) must be of type string, null given

This happens when $page_title is not available.
3. Module instability
When I try different routing approaches, either:
index page breaks, or
book detail page breaks
⚙️ Routes I tried
I tested several patterns:

/library/{id}
/library/{id}/{slug?}
/library/{any}

I also attempted manual parsing via REQUEST_URI, but it caused conflicts with the framework router.
🧠 Context
Library module is currently using legacy PHP includes (includes/index/book.php, main.php)
Routing is handled both by JohnCMS router and manual logic inside the module
Slug is currently not stored or validated against database (only decorative)
❓ What I’m looking for
I would like to know the best practice to:
Support SEO-friendly URL like /library/1/slug
Keep /library/1 working without redirect issues
Avoid breaking /library/ index route
Handle optional slug safely without interfering routing
Prevent null values in NavChain / page titles
🙏 Any advice appreciated
If anyone has experience implementing SEO URLs in JohnCMS modules (especially legacy + router hybrid setup), I would appreciate any clean architectural approach or recommended pattern.
Thanks in advance.

.
Кадило крутится, лавэха мутится

This has already been implemented in the current development version of JohnCMS and is planned for release in the next few weeks.

If you need it right away, you can take a look at the current implementation in the repository:

https://github.com/johncms/johncms/blob/9.x/modules/library/config/routes.php

Please note that the Library module has been significantly refactored since the legacy version, so the implementation is quite different from the code you're currently working with. It should be viewed more as a reference than a drop-in solution.

.

Thank you for the information. I understand. I will wait for the official update from JohnCMS. I appreciate your help and guidance.

.

Thank you for your reply.

I looked at the new Library module in the GitHub repository and downloaded it to study the implementation. I also tried replacing my current Library module with the new one, but I couldn't get it working. It resulted in several errors, which I assume is because my project is still based on the legacy version while the repository has already been heavily refactored.

Could you please explain the correct installation process step by step?

For example:

  1. Which files and folders need to be copied?
  2. Are there any new dependencies or Composer packages that must be installed?
  3. Do I need to update the routing configuration or register any new services?
  4. Are there any database changes or migrations required?
  5. Is there anything else that must be configured before the new Library module will work?

I would really appreciate a step-by-step guide, as I would like to learn the new architecture and migrate my project correctly.

Thank you very much for your time and support.

@simba

.
Кадило крутится, лавэха мутится

Unfortunately, it's not possible to install just the new Library module into a legacy JohnCMS installation.

The current development version has been significantly refactored, so the new Library depends on changes made throughout the framework, not only inside the module itself. That's why simply copying files results in errors.

If you want to use the new Library implementation now, it will be much easier to install the current development version of JohnCMS from the repository instead of trying to adapt the new module to an older release.

Installation instructions are available here:
https://github.com/johncms/johncms#installation-from-repository

Otherwise, I'd recommend waiting for the next official release if you prefer to stay on a stable version.

Всего: 5