Просмотр поста #562106: How to implement SEO-friendly Library URLs in JohnCMS without breaking routing

.
drevils

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.