Angular 6 Dynamic Views with Auxiliary Routes and clean URL's

随声附和 提交于 2020-01-02 08:48:34

问题


In my Angular 6 project, I have some components that have a sidebar, and some of them don't. I tried to do this with auxiliary routes and it worked, but the URL's are ugly as ...!

--

What I do:

const routes: Routes = [
{
    path: 'login',
    component: LoginComponent
},
{
    path: 'search',
    component: SearchComponent
},
{
    path: 'sidebar',
    outlet: 'sidebar',
    component: SidebarComponent
}

which gives me them possible URL's

https://localhost:4200/login - (login without sidebar)

https://localhost:4200/login(sidebar:sidebar) - (login with sidebar)

https://localhost:4200/search - (search without sidebar)

https://localhost:4200/search(sidebar:sidebar) - (search with sidebar)

--

The desired result is just to have the URL's /login and /search, but the search with the sidebar and the login without the sidebar. How can I do this?

Are auxiliary routes the right way to do this? Or is there another way to do this right?

来源:https://stackoverflow.com/questions/50834187/angular-6-dynamic-views-with-auxiliary-routes-and-clean-urls

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!