skip to Main Content

I’m trying to build a page in sveltekit that will display a list of document names, and when you click on a name it will display the corresponding document (which is a static HTML file).

I’m using a table:

    <tbody>
    {#each docs as doc, i}
        <tr>
            <td>{i + 1}</td>
            <td><a href={`docsDir/${doc.fileName}`}>
                {doc.docTitle}</a></td>
        </tr>
    {/each}
    </tbody>

Where should I put docsDir so that it will be found, or is there a better way to do this?

2

Answers


  1. It really depends on your intention. You could display it in the header of your table, for instance:

        <table>
        <thead>
            <tr>
                <td>{docsDir}</td>
            </tr>
        </thead>
        <tbody>
        {#each docs as doc, i}
            <tr>
                <td>{i + 1}</td>
                <td><a href={`docsDir/${doc.fileName}`}>
                    {doc.docTitle}</a></td>
            </tr>
        {/each}
        </tbody>
        </table>
    

    but, in general, it is up to you to decide what your purpose is and you need to present it to us, so we will provide you facts rather than opinions. I have given you a way you can display docsDir, which may or may not be compliant with your goals. If it’s not compliant with your goals, then you will need to provide further information about your task so we can better fulfill your goals.

    Login or Signup to reply.
  2. I feel it would be simpler to have the links be absolute:

    href={`/docsDir/${doc.fileName}`}
    

    and thus have docsDir as a direct child of your static assets directory, i.e. /static/docsDir.

    I’d also consider renaming docsDir to docs for clarity (unless it is already used somewhere else in your routing tree, for instance /src/routes/docs).

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search