Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
277 views
in Technique[技术] by (71.8m points)

Route multiple components with the same base url in Angular

I am pretty new to Angular and I am creating an app that has nested information in pages (like in a file explorer) the app works fine when using the buttons to navigate, but I want the users to be able to go directly to the information they are looking for by pasting a link in their browser. For that, I need to redirect the users using 'www. mysite.com/explorer/page1' and 'www. mysite.com/explorer/page1/document1' to the same component who will take the URL and make the requests needed to the server. I was unable to find how to do that. I would really appreciate it if you could explain it to me.

Thank you in advance!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Ok, I found an answer after reading a lot about routing in Angular and taking a break to rethink my point of view.

To achive that you can create a child of the base url you want to redirect from, and then assing your component to the '**' path in teh child routing which means all your urls will go to the same component, and to solve the probelm of showing different information we can take the URL and then render the componen according to the information there.

const routes: Routes = [
    {path: 'explorer/', component: ExplorerComponent, children: [
        {path: '**', component: ExplorerComponent}
      ]
    }
];

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...