Coder Social home page Coder Social logo

Folder name as parameter about routify HOT 17 CLOSED

roxiness avatar roxiness commented on September 1, 2024
Folder name as parameter

from routify.

Comments (17)

Wolfr avatar Wolfr commented on September 1, 2024

What I am trying to do:

  • I have a list view A and a list view B
  • I have a detail view whose data depends on whether you came from A or B, and shows content based on an id in the list view

I am trying to find the most elegant way to implement this.

from routify.

Wolfr avatar Wolfr commented on September 1, 2024

Here's some code I was trying:

import { url } from '@sveltech/routify';

then

<a href={$url('/:language/:detail', { detail: character.romaji, language: 'hiragana'})}>
    {character.character}
</a>

from routify.

jakobrosenberg avatar jakobrosenberg commented on September 1, 2024

What you're showing in the screenshot should be fully supported.

Any chance you can give a specific example of your scenario in the second post?

from routify.

Wolfr avatar Wolfr commented on September 1, 2024

I created a branch for my specific situation.

https://github.com/Wolfr/kana-master-svelte/tree/replay

Here you can see {language} is undefined, I would expect it to be "hiragana". I did export let language from the detail.

Screenshot 2020-01-04 at 22 00 48

from routify.

rixo avatar rixo commented on September 1, 2024

Test says there's no problem with param in folder, in basic cases.

from routify.

jakobrosenberg avatar jakobrosenberg commented on September 1, 2024

I think this probably comes down to the "drafty" documentation.

The way it's intended is that if a page has a [parameter], the parameter is passed to the page as a prop. In the case of a folder, the parameter is passed to the _layout.svelte (which for all intends and purposes could be considered _folder.svelte).

To access all parameters, you can use the $params helper.

from routify.

rixo avatar rixo commented on September 1, 2024

@Wolfr You repo is giving an error about a missing component, but once that commented out, I can confirm the problem.

For the record, I hadn't pulled the last master. The test is indeed falling with last Routify version, and was passing with the previous version. So what you're trying to do was possible but isn't anymore.

Accessing parent params from page components' props might not be supported in the future. For now, the recommended approach is to use the $params helper, like @jakobrosenberg said.

from routify.

Wolfr avatar Wolfr commented on September 1, 2024

I found a way to solve my problem but it is kind of wieldy.

$: Object.keys($params).forEach(function eachKey(key) { if (key == "language") { language = $params[key]; }});

This to make sure that the language param works.

from routify.

Wolfr avatar Wolfr commented on September 1, 2024

My evening-of-coding result https://kana-master-svelte.now.sh :)
Source code: https://github.com/Wolfr/kana-master-svelte

Any ideas for optimizations regarding routing welcome.

from routify.

rixo avatar rixo commented on September 1, 2024

What about?

$: ({ language } = $params)

I don't think it is a good idea to only set the variable if the key is effectively present in $params. You'd better stay in sync with what's in there. If the value is required and not present, you have a problem that you need to fix anyway, elsewhere.

Continuing to use a stale value doesn't seem like the proper solution to me. If your code really can't live without a value for language, I think throwing an exception would be better.

from routify.

Wolfr avatar Wolfr commented on September 1, 2024

Thank you, that is smart and looks cleaner. Not sure if I fully understand it though 😝

Now, currently, if I use the back button in my app now, regardless of using your solution or mine, it throws an error.

I have the feeling that I don't know enough about how reactive stores should interact with the parameters, I am a bit out of my depth here. At this point it could be a bug in my logic or a bug in the framework.

I am linking to two levels back, is this supported behavior or not?

<Button variant="ghost" icon="chevron-left" href="{$url('../../')}">Back</Button>

Screenshot 2020-01-05 at 13 16 57

Sorry if this feels too much like QA for my app, but since Routify is relatively new I thought I would ask.

from routify.

jakobrosenberg avatar jakobrosenberg commented on September 1, 2024

That is supported. I was writing my router suggestions here, but eventually figured it would be easier to just show my idea. I'll push a makeover very soon.

from routify.

jakobrosenberg avatar jakobrosenberg commented on September 1, 2024

There was a bug in Routify, which updated the internal store before the page/layout had been destroyed, meaning that your component could be left hanging without the needed data. Pushing a fix now.

from routify.

jakobrosenberg avatar jakobrosenberg commented on September 1, 2024

I got very confused by the navigation on your site. The top level navigation seemed to be at the bottom below-the-fold; Katakana seems to be a subset of Hiragana, judging by the browser address and the navigational highlighting of links didn't work for Hiragana Disgraph, since Hiragana Monograph was on /index and Hiragana Disgraph was on hiragana-digraphs.

I can be a bit of a robot at times and others may find the UX intuitive.

I've rewritten a bit of your code to show off an alternative here.
https://public-fkf8u37xb.now.sh/

https://github.com/jakobrosenberg/kana

from routify.

rixo avatar rixo commented on September 1, 2024

Just to clarify...

This:

$: ({ language } = $params)

is equivalent to this:

$: language = $params.language

ES destructuring + Svelte reactive declaration... Said otherwise, lots of sugar!

from routify.

Wolfr avatar Wolfr commented on September 1, 2024

Hi Jakob, for your informatiom. This is a rewrite (WIP obviously :)) of an iOS app. This is supposed to be a mobile app with a tab bar in the end, you can see what is supposed to look like at http://kanamaster.com/ .

The relationship between the two that Katakana and Hiragana are two scrips, and both have digraphs.

I'll check your code to see what I can learn!

from routify.

jakobrosenberg avatar jakobrosenberg commented on September 1, 2024

That explains it. :P

The gist of what I did with your code was that I moved all the individual pages into /:graph/:language and unified them in one page and treated each graph/language as a prop to be fed to the maingrid.

You can shift this around to your liking.

from routify.

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.