pnp / generator-teams

A Yeoman Generator for Microsoft Teams
https://pnp.github.io/generator-teams
MIT License
428 stars 112 forks source link

Question/Guidance : Using Routers with Yo teams based generated project #284

Closed siddharth-vaghasia closed 2 years ago

siddharth-vaghasia commented 2 years ago

Hello,

I am trying to figure out how to use routers with yo teams-based generated project...yo teams generated project structure has the first tab which gets rendered with URL /tabname

This is because of tabname/index.html inside the public folder basically indirectly using below line

teamsppReactRouter.render(teamsppReactRouter.TabName, document.getElementById('app'), {});

Now when we wanted to create a new page we have below option to

Create one more tab by running yo team again on the same project and it will create a new tab component and corresponding index.html insider public folder but this tab then acts as a single page application because of its own life cycle

I am trying to understand how to use React router concept inside the same project structure where I can create multiple pages inside the same project structure and use routers to redirect users to different routes and one of them being the main route(root).

Tried a few samples and code references but most of them work well and use routers/routes when the project is generated by using a stand-alone react app and not via yo teams...

As there are multiple ways to create a team's application... Just trying to figure out how yo teams being a native teams app generator library allow to use routers and support multiple pages with one application lifecycle and not each tab/page as a single page application.

Any help/advice is appreciated...

wictorwilen commented 2 years ago

Thanks for reaching out. You are correct that the default scaffolding will create a new page for each "interface" (tab, config etc). That is what is being scaffolded. But - there is nothing prohibiting you from changing this into more of a single page app and use a router. All you need to do is to update the manifest so that all pages/tabs points to the same page (for instance /myTab/index.html) and then just append the has for each page (for instance /myTab/index.html, /myTab/index.html#config, /myTab/index.html#anotherTab etc.)

wictorwilen commented 2 years ago

This is also a good idea for a sample!

siddharth-vaghasia commented 2 years ago

@wictorwilen - thanks for the reply and advice... I actually tried that but could not make it work but probably that is because of my limited knowledge of routers.... I am going to give it another try to make it work..... If I could make it work, would love to add it as a sample in teams app sample gallery...thanks anyways..!!!

RickVanRousselt commented 2 years ago

Hi @siddharth-vaghasia ,

I've assigned this issue to you. Let us know if you need help with it. And thanks again for helping out ❤️

siddharth-vaghasia commented 2 years ago

@RickVanRousselt - thanks...I am assuming we should add this to teams app sample gallery ?

https://pnp.github.io/teams-dev-samples/

wictorwilen commented 2 years ago

@siddharth-vaghasia - yes, that would be the best location for it, and for you to showcase your skills!

siddharth-vaghasia commented 2 years ago

@wictorwilen @RickVanRousselt - We have added the sample, Thanks @kunj-sangani for this help on making this work :)