You define a friendly URL, load the page, and the address reads
/discord/discord/invite/abc123. The route works, nothing errors, and
the duplication looks like a typo somewhere you cannot find.
It is not a typo. Invision Community prepends topLevel to
every friendly path in the file. Repeat it in the path and you get it
twice.
Wrong
{
"topLevel": "discord",
"pages": {
"myapp_invite": {
"friendly": "discord/invite/{@key}",
"real": "app=myapp&module=discord&controller=invite"
}
}
}
Produces /discord/discord/invite/abc123.
Right
{
"topLevel": "discord",
"pages": {
"myapp_invite": {
"friendly": "invite/{@key}",
"real": "app=myapp&module=discord&controller=invite"
}
}
}
Produces /discord/invite/abc123.
The top-level landing page is the exception, and it is an empty string
The obvious guess for "the page at /podcasts" is
"friendly": "podcasts". That gives you
/podcasts/podcasts/. Every core application uses an empty
string instead:
grep -A2 '"topLevel"' applications/forums/data/furl.json
# "topLevel": "forums",
# "pages": { "forums": { "friendly": "", ... } }
So:
{
"topLevel": "podcasts",
"pages": {
"myapp_index": { "friendly": "", "real": "..." },
"myapp_show": { "friendly": "{#id}-{?}", "real": "..." },
"myapp_episode": { "friendly": "episode/{#id}-{?}","real": "..." }
}
}
Which gives /podcasts/, /podcasts/12-my-show/ and
/podcasts/episode/34-my-episode/.
The placeholder types are not interchangeable
A second way to lose an afternoon. {#name} is a number
and {@name} is a string:
"friendly": "invite/{#key}" <-- a hex key becomes 0. Every link resolves to the same record.
"friendly": "invite/{@key}" <-- correct for anything non-numeric
Use {?} for a slug you do not intend to read back — the
human-readable part of /podcasts/12-my-show/.
Check it rather than assume it
Neither mistake throws. Both produce URLs that resolve, so tests pass and the page loads. Print the URLs once, from code, and read them:
printf( "%s\n", Url::internal(
'app=myapp&module=x&controller=y&id=1', 'front', 'myapp_show', array( 'the-slug' )
) );
This matters more than tidiness for anything a person keeps. A podcast feed address is permanent once somebody subscribes; an invite link gets pasted into chat and printed on things. Fixing the URL later means breaking every copy of it that already exists.
Related application: Podcasts — Podcasts gives each show a readable, permanent feed address like /podcasts/feed/12-my-show, because that URL cannot be tidied up once anybody has subscribed to it.
Recommended Comments