Next.js Sub-Pages for parameterized routes - next.js

Right now, my routing looks like this:
https://app.com/users opens pages/users/index.js
https://app.com/users/:userid opens pages/users/[id].js
I want to create route, for example:
https://app.com/users/:id/friends -> show all friends for the user
or even
https://app.com/users/:id/friends/:friendId -> show a specific friend
I have tried
pages
users
index.js
[id].js
friends
index.js
[friendId].js
but i can only reach users/friends and not `users/:id/friends``
How do i set my pages directory so i can use this sort of routing?
Also, I want to be able to access id and friendId in the context of getServerSideProps...

If you don't get the answer description well, pls follow the diagram I made.
If you want this https://app.com/users/:id/friends, then you should create something like this:
pages/users/index.js/[id]/index.js/friends.js
So to make this clear, you have a folder name pages (where all pages folder and files are), then you have a user folder (this takes an index.js which means user path). Now in the user folder, you have to create a folder named [id], in this folder you should create a file name index.js, this index.js stand for the :id. The last thing is to create the friend.js in the [id] folder.
Something like this.
pages ----------------- Main folder
users ------------- A folder inside `pages` folder
index.js ------- A file inside `users` folder == `https://app.com/users`
[id] ----------- A folder inside `users` folder
index.js ---- A file inside `[id]` folder ==`https://app.com/users/:id`
friends.js -- A file inside `[id]` folder == `https://app.com/users/:id/friends`
If you want something like this https://app.com/users/:id/friends/:friendId
Then you will have to do something like this:
pages ------------------------- Main folder
users --------------------- A folder inside `pages` folder
index.js --------------- A file inside `users` folder == `https://app.com/users`
[id] ------------------- A folder inside `users` folder
index.js ------------ A file inside `[id]` folder ==`https://app.com/users/:id`
[friends] -------- A folder inside `[id]` folder
index.js ------ A file inside `[friends]` folder
friendId.js --- A file inside `[friends]` folder

You can use Dynamic Routing syntax in your folders instead of a file in order to nest them (create a folder [id] instead of a file [id].js). For your specific example it would look like this:
pages
users
index.js
[id]
friends
[friendId].js

Related

Sbt in project plugin, how to structure them?

We do have a custom plugin as a single file in our project folder:
acme-project
|- ...
|- project
| |- CustomPlugin.scala
object CustomPlugin extends AutoPlugin {
// ...
That was simple and easy until that plugin started to grow...
In the first step, we added more classes/objects to the same source file. However, it continues to grow and I would like to add more structure via packages.
acme-project
|- ...
|- project
| |- CustomPlugin.scala
| |- SupportingClass.scala
| |- acme
| | |- plugin
| | | |- PackagedClass.scala
My CustomPlugin seems to be able to use the SupportingClass from the folder, whenever this class declare another package. However, I cannot use the PackagedClass :
[error] /~/acme-project/project/CustomPlugin.scala:1:8: not found: object acme
[error] import mega.plugin.PackagedClass
[error]             ^
I tried to add one src/main/scala folder but have the same kind of import errors.
So, I would like to know if there are ways to create large/structured plugins inside a project without making a complete one?
I would like to keep the simplicity of this format where I do not have to publish my plugin. Having it inside a dedicated module would be ok.
Thanks
One way to do this is to restructure your plugin as its own sbt project, then load it as a module dependency in your project's plugins.sbt.
Move the code to its own directory. This can be anywhere you like, e.g.:
acme-project/project/my-custom-plugin/
acme-project/my-custom-plugin/
some-other-path/my-custom-plugin/
Write a my-custom-plugin/build.sbt with at least these settings:
enablePlugins(SbtPlugin)
sbtPlugin := true
scalaVersion := "2.12.16"
name := "my-custom-plugin"
Add it to your project as a module dependency in acme-project/project/plugins.sbt:
// For acme-project/project/my-custom-plugin/
val myCustomPlugin =
project in file("my-custom-plugin")
// For acme-project/my-custom-plugin/
val myCustomPlugin =
ProjectRef(file("../../my-custom-plugin"), "my-custom-plugin")
// For some-other-path/my-custom-plugin/
val myCustomPlugin =
ProjectRef(file("/path/to/my-custom-plugin", "my-custom-plugin")
dependsOn(myCustomPlugin)
You only need one of those val myCustomPlugin = lines, depending on where you put your my-custom-plugin/ directory.

Dynamic routing with multiple parameters in Next js - File Structure

I want to create dynamic pages in nextjs to match the following route users/[user]/[dashboard]. My file structure
pages/
users/
-[user].js // will match for /users/123
- index.js // will match for /users
dashboard/
- [dashboard].js // will match for /users/1234/ABCD
I'm only receiving the [user] in the query param and not the [dashboard] inside the [dashboard].js . Can someone explain how to arrange file structure to match users/[user]/[dashboard]
To match the following dynamic routes users/[user]/[dashboard] you can structure your pages folder as follows:
pages/
users/
index.js // Matches `/users` route
[user]/
index.js // Matches `/users/user123` routes
[dashboard]/
index.js // Matches `/users/user123/dashboardABC` routes

delphi DirectoryListBox Get selected directory name

I'm using a dirListBox in delphi. I cant get the sub directory name of the directory selected. It gives me the root direct name instead. How do I get the selected directory name?
dirListBox.Directory returns the parent directory, not subdirectory.
The only way I could get the correct names was using the itemindex.
The itemindex is updated when you click or move the cursor to the directory.
fMain.eProject.Text:=fProject.dirlistBox.Items[fProject.dirListBox.ItemIndex];
fMain.ePath.Text:=fProject.dirListBox.GetItemPath(fProject.dirListBox.ItemIndex);

Is it possible to add properties to multiple files after they have been uploaded to artifactory?

As the title says. Due to a lack of understanding about how best to query files in artifactory I now have a situation where I have a few hundred files I need to add the same properties to.
Can this be done in bulk?
the folder structure looks like this:
repository
|
|- main folder
|
|- type
|
|- language1
|
|-sub-folder1
|-sub-folder2
|-file1
|-file2
...
...
...
Each sub-folder can have around 5 files, each language folder can have many sub-folders.
Sure it is.
You have two main options.
The first one is to use the Set Item Properties REST API on the relevant folder with the "recursiveProperties=1".
The second option, which I believe is better, will be to use the JFrog CLI to set properties on existing artifacts. This options will provide you with the ability to define a more complex logic on setting the properties.

How programmatically to export additional .class files with my JAR

I need the .class files (not related to the source files in the project) located in one of the folder inside the project to be exported with JAR too.
If I do export my project with "Deployable plug-ins and fragments" and specify the elements I need to export in build.properties file it does export all I need correctly.
Same I want to do programmatically.
When I create the JAR file with
final JarPackageData jarPackage = jarCreator.create(project, jarLocation);
in create function I set the options like
jarPackage.setJarLocation(jarLocation);
jarPackage.setExportClassFiles(true);
jarPackage.setManifestLocation(manifestFile.getFullPath());
jarPackage.setIncludeDirectoryEntries(true);
jarPackage.setExportWarnings(true);
jarPackage.setGenerateManifest(false);
jarPackage.setOverwrite(true);
jarPackage.setElements(elementsToExport.toArray());
I did check that all the files I need are in the list elementsToExport
final IJarExportRunnable jarExport = jarPackage.createJarExportRunnable(owner.getShell());
try{
owner.getContainer().run(true, true, jarExport);
}
The result is:
It does export the selected folder to the exported JAR file
It does export the text file (for example) located in this folder.
But it does not export the .class files located in this folder.
Please, let me know if you have any glue how to configure JarPackageData to be able to export what ever is in the selected folder!
I am not sure about the particular build system you are using, but Jar files are zip archives, so if you really need to, you can open them up and insert the extra files yourself. Better yet, write a script to do this.

Resources