Open tv42 opened 4 years ago
Currently route nodes are either static or parameterized. That's not to say flexibility can't be added to the nodes, just that I haven't come across a justifying use case.
For what it's worth, out of curiosity I tested the same with Sapper and it works as expected there (though with a lot more bureaucracy in handing the data over):
<script context="module">
export function preload(page, session) {
const { slug } = page.params;
return { slug };
}
</script>
<script>
export let slug;
</script>
<p>slug {JSON.stringify(slug)}</p>
It seems counterintuitive to force the sue deeply nested single files if you have several parameters (like when navigating user/[userId]/order/[orderID]/product/[productID]/review.svelte
)
Would be lovely to have a file test[slug].svelte to correspond to test/[slug].svelte. I suggest that an error is provided if you have both the folder structure and the file naming structure.
I don't like the idea of magic slash that sometimes is there sometimes isn't. test/[slug].svelte
should match test/foo
but not testfoo
; test[slug].svelte
should match testfoo
but not test/foo
.
I'd like to support artificial paths. This is an issue I come across myself from time to time.
Not sure what the best syntax would be for the following examples.
Nesting statics
helpful
explanatory
path
index.svelte
Nesting dynamics
[year]
[month]
[day]
index.svelte
Nesting both
year
[year]
month
[month]
day
[day]
index.svelte
### Option 1: Treat dynamics as folders
statics: helpful[]explanatory[]path.svelte dynamics: [year][month][day].svelte both: year[year]month[month]day[day].svelte
**Pros**
1. It's clean
2. Dynamics-are-treated-as-folders is an easy concept to follow
**Cons**
1. It prevents this type of syntax `[year]-[month]-[day].svelte`.
2. Not sure how I feel about nesting statics.
a. Alternatively we can also fake a nested structure of statics by adding a separate folder delimiter.
b. Having both a folder delimiter and "auto" folders is confusing.
### Option 2: Create a folder delimiter
What's a good delimiter? It has to be safe across OS'es and unsafe in URLs. We don't want safe URL characters as they could conflict with actual URLs.
It is actually true - the [year]-[month]-[day].svelte syntax could be usefull.
|
is a great delimiter in my opinion... but also a bit of a cumbersome typing to have year|[year]|month|[month]|day|[day].svelte
May I suggest that
|
then only the char |
is to determine a new level|
then the char [
will determine a new levelExamples:
statics: helpful|explanatory|path.svelte
dynamics: [year][month][day].svelte
both: year[year]month[month]day[day].svelte
Specific [year]-[month]-[day]|.svelte
I thought |
pipes were illegal characters, but I could easily be wrong.
Can we please not contaminate this issue with magic slash alternatives?
I'm not sure where else to address how filenames should be parsed. Any aspect affected by a solution should be considered.
Please note, I'm not campaigning for magic slashes, just trying to provide an overview of the different options that are available for filename parsing.
routify 1.9.7
create
src/pages/test[slug].svelte
:visit
/testfoo
, observe outputExpected "foo" for both.