Angular 2: hide route component - apache

I have a website built around angular 2 running on Apache. The same website (and same API) is used by different "groups". Let's say there are two groups: bees and wasps. My angular routing file looks like this:
{
path: '',
redirectTo: 'groupe/1',
pathMatch: 'full'
},
{
path: 'groupe',
children: [
{
path: ':groupe',
children: [
{
path: '',
component: HomePage,
},
...
To access a group, I can then simply go to http://myws.com/group/1 (for bees) and http://myws.com/group/2 (for wasps). Pages are then basically the same for each group (with different content, loaded from an API), like: http://myws.com/group/1/page/21.
Now the tricky part. First I want to access each "group" from a simplified, explicit URL: like http://myws.com/bees. I can do this by adding the following code to the router :
{
path: 'bees',
redirectTo: 'groupe/1',
pathMatch: 'prefix'
},
Problem is, the route changes in the URL back to /group/1. Is there a way to make the /bees permanent, hiding /group/1 ?
Now, I also want to access my bees group from a specific domain, like http://www.bees.com. Pages should render like http://www.bees.com/page/21 Is there a way with angular or Apache to do this?

Well, on the Angular side (meaning everything after the .com), you can do like so
export const bugRoutes: Routes = [
{ path: 'bees', canActivate: [MyBeeGuard], children: [
{ path: '', component: BeeHomeComponent },
{ path: '**', component: BeeHomeComponent }
]},
{ path: 'wasps', canActivate: [MyWaspGuard], children: [
{ path: '', component: WaspHomeComponent},
{ path: '**', component: WaspHomeComponent}
]},
{ path: '**', component: ChoseBugHomeComponent }
];
This way, your user will be redirected to any bug home, no matter the route. And if he inputs no route at all, he will be redirected to a component that "allows" him to chose which bug to chose

Related

Two doc pages in docusaurus [duplicate]

As I know, Docusaurus supports customized pages, but is there a way to have two docs in one Docusaurus project?
The original Navbar items have:
Docs
Blog
...
I want to have something like this:
Docs 1
Docs 2
Blog
...
I know I can make many subfolders just in one doc, but for some reason, I want a two Docs structure, which gives me a cleaner way to access docs.
If Docusaurus cannot offer this feature currently, I want to ask is there other documentation frameworks offer this feature?
You need to use the plugin-content-docs.
First, create the other docs folder, like docs, docs-api, docs-system.
(1) In your docusaurus.config.js file, configure your "default" docs:
(module.exports = { // start of the module.export declaration
[…]
presets: [
[
'#docusaurus/preset-classic',
{
docs: {
routeBasePath: 'docs',
path: 'docs',
sidebarPath: require.resolve('./sidebars.js'),
lastVersion: 'current',
onlyIncludeVersions: ['current'],
},
theme: {
customCss: require.resolve('./src/css/custom.css'),
},
},
],
],
[…]
}); // end of the module-export declaration
(2) Now, the magic!: in the same file, configure your other documents:
(module.exports = { // start of the module.export declaration
[…]
plugins: [
[…]
[
'#docusaurus/plugin-content-docs',
{
id: 'docs-api',
path: 'docs-api',
routeBasePath: 'docs-api',
sidebarPath: require.resolve('./sidebars.js'),
},
],
[
'#docusaurus/plugin-content-docs',
{
id: 'docs-system',
path: 'docs-system',
routeBasePath: 'docs-system',
sidebarPath: require.resolve('./sidebars.js'),
},
],
],
[…]
}); // end of the module-export declaration
(3) Now you probably want these documents in your NavBar, right? So add then!
(module.exports = { // start of the module.export declaration
[…]
navbar: {
hideOnScroll: true,
title: 'your title',
logo: {
alt: '',
src: 'img/favicon.ico',
},
items: [
{
to: '/docs/Intro', // ./docs/Intro.md
label: 'Docs Title',
position: 'left',
activeBaseRegex: `/docs/`,
},
{
to: '/docs-api/Intro', // ./docs-api/Intro.md
label: 'API',
position: 'left',
activeBaseRegex: `/docs-api/`,
},
{
to: '/docs-system/Introducao', // ./docs-system/Intro.md
label: 'My System',
position: 'left',
activeBaseRegex: `/docs-system/`,
},
],
},
[…]
}); // end of the module-export declaration
IMPORTANT
Sometimes you will modify your docusaurus.config.js and will not "work", so close the docusaurus service (just Ctrl+C in your terminal/power shell) and restart it -- I could have saved a few hours if a had known this before.
If you don't have the plugin-content-docs plugin, just install it:
npm install --save #docusaurus/plugin-content-docs
ROADMAP
I had a hard time figuring this out. What I did was download the whole docusaurus project, get the website part, trim everything that I did not need and this is what I got.
REFERENCES (Update 2022/03/02)
https://docusaurus.io/docs/docs-multi-instance
This solution worked for me. Using the 'autogenerated' sidebar in Docusaurus v2.0.0-beta.15
sidebars.js
/** #type {import('#docusaurus/plugin-content-docs').SidebarsConfig} */
const sidebars = {
// tutorialSidebar: [{type: 'autogenerated', dirName: '.'}],
newone: [{type: 'autogenerated', dirName: 'newone'}], // foldername
newtwo: [{type: 'autogenerated', dirName: 'newtwo'}], // foldername
};
module.exports = sidebars;
docusaurus.config.js
navbar: {
title: 'My Site',
logo: {
alt: 'My Site Logo',
src: 'img/logo.svg',
},
items: [
// {
// type: 'doc',
// docId: 'intro',
// position: 'left',
// label: 'Tutorials',
// },
{
type: 'docSidebar', // docSidebar
position: 'left',
sidebarId: 'newone', // foldername
label: 'NEWONE', // navbar title
},
{
type: 'docSidebar', // docSidebar
position: 'left',
sidebarId: 'newtwo', // foldername
label: 'NEWTWO', // navbar title
},
{to: '/blog', label: 'Blog', position: 'left'},
{
href: 'https://github.com/facebook/docusaurus',
label: 'GitHub',
position: 'right',
},
],
},
Your docs folder:
docs/
newone/
intro.md
newtwo/
intro.md
I tried this way and it's working.
[Edit 1]: But when I select API then both API and Docs in Navbar becomes green. Can you tell us what's the reason behind this #Yangshun Tay and can you suggest the edit for that?
[Edit 2]: I read the documentation, it's written in #docusaurus/theme-classic, if we set activeBasePath property then links with that common path (docs in this case) will have active attribute.
sidebar.js
module.exports = {
someSidebar: {
Docusaurus: ['doc1', 'doc2'],
Features: ['doc3']
},
someOtherSidebar: {
Test: ['mdx']
}
};
docusaurus.config.js
The navbar links are like this -
links: [
{
to: 'docs/doc1',
// activeBasePath: 'docs', // [Edit 3]
label: 'Docs',
position: 'left'
},
{
to: 'docs/mdx',
label: 'API',
position: 'left'
},
]
Folder structure of docs folder is like this -
docs
├── docs1.md
├── mdx.md
Regardless of whether you're using v1 or v2, the sidebars.js configuration can contain multiple keys, each having its own sidebar.
You need to use the doc type in docusaurus config. I think the "to" type is for pages not docs.
To make the sidebar correct, you need to also set the activeSidebarClassName value in the config to let it know which sidebar (among those you exported in the sidebars.js) you want to use for this doc.
activeSidebarClassName: 'navbar__link--active',
https://docusaurus.io/docs/api/themes/configuration#navbar-doc-link
Setting up Docusaurus to be multi-instance spans changes across many files. To make it easier to set up, I've created a base install with all the necessary changes to go multi-instance, and have released it as a GitHub template.
Fork it here:
mg0716/docusaurus-multi
Many of the changes in this repo were a result from #d-kastier's original comment.
Very open to feedback and pull requests, so feel free to give it a shot!
on my test, you MUST Include path "docs-xxxxxxxxx" ! do not create another name such "education" you will get page crash !

Vue Router 4 with nested children and params-only

I'd like to make my Vue 3 app, using Vue Router 4, to follow a pattern with nested children. This is my list of routes:
export default VueRouter.createRouter({
history: VueRouter.createWebHashHistory(),
routes: [
{
name: 'booking-start',
path: '/',
component: BookingStep1Component,
children: [
{
name: 'booking-step-1',
path: '/:from_gid/:to_gid',
component: BookingStep1Component,
children: [
{
name: 'booking-step-2',
path: ':date_from/:date_to',
component: BookingStep2Component,
children: [
{
name: 'booking-step-3',
path: ':time_from/:time_to',
component: BookingStep3Component
},
]
}
]
}
]
}
]
})
So if I go the the url /# I would like to get the BookingStep1Component displayed, same goes with /#123/456. If I go to /#123/456/2022-01-01/2022-02-28, I'd like to see BookingStep2Component, and if I go to /#123/456/2022-01-01/2022-02-28/10:00/13:00, I'd like to see BookingStep3Component. But things get mixed up somewhere and I do not see the right component at some stage.
Is there anything obvious I am missing here?
Not sure, but I do not use a "/" at the beginning of childs like at booking-step-1.
Although I have not used paths, beginning with a param ... should work, but I would try it out.

Binding Vuex data to vue-meta

I'm working on a blog and I'm having a hard time trying to plug Vuex and Vue-meta. Here is the code :
On the article template, I use a v-for="article in selectedArticle" and a computed property to display the correct article from Vuex
selectedArticle() {
return this.$store.state.articles.filter(article => article.id == this.$route.params.id);
},
I'm trying to use Vue-meta in this way :
metaInfo: {
title: ???,
meta: [
{ charset: 'utf-8' },
{ vmid: 'description', name: 'description', content: ???.id },
{
'property': 'og:image',
'content': https://api.someurl.com/article/ + ???.id,
'vmid': 'og:image'
}
]
}
I think one way to do it would be to bind the vuex data retrieved in SelectedArticle to the actual data property of the component, and then use title : this.article.title in metaInfo.
But I don't know how to do it and I'm not sure if this is the right way.
Any other suggestions?
Thank you very much

Is possible to have parameters on the moleculer-web route path?

Is there a way to add parameters on a moleculer-web route path?
I would like to add a parameter in the path to avoid to add in each alias.
I have tried to add a parameter, but after that, I could not reach the endpoint anymore
broker.createService({
mixins: [ApiService],
settings: {
routes: [
{
path: "/lng/:lng",
aliases: {
"GET /secret": [
auth.isAuthenticated(),
auth.hasRole("admin"),
"top.secret"
]
}
}
]
}
});
Thanks
No, you can use params in aliases only:
broker.createService({
mixins: [ApiService],
settings: {
routes: [{
path: "/lng",
aliases: {
"GET /:lng/secret": [
auth.isAuthenticated(),
auth.hasRole("admin"),
"top.secret"
]
}
}]
}
});

Vue.js create dynamic AJAX response based multiple components

I am trying to create an SPA using dynamic server response.
For e.g. data returned is:
components: [
{
name: "Parent1",
data: {...},
children: [
{
component: {
name: "Child1",
data: {...},
children: []
}
},
{
component: {
name: "Child2",
data: {...},
children: []
}
}
]
},
{
name: "Parent2",
data: {...},
children: [
{
component: {
name: "Child1",
data: {...},
children: []
}
}
]
}
]
What I would like to do is define parent components and children separately.
i.e. Components list:
- Parent : Common parent with data1 and data2 displayed, instantiates Children as needed
- Child1
- Child2
Anyone have any ideas for the best approach?
You may do like this:
Parent API URL: www.example.com/api/parent/parent_id (generally known as API endpoint)
Server Response:
{
data: {
type: "Parent",
id: "parent123",
name: "Parent 1",
children_ids: ["c1", "c2", "c3"]
},
included: [
{type: "Child", id: "c1", name: "Child 1", ...},
{type: "Child", id: "c2", name: "Child 2", ...},
{type: "Child", id: "c3", name: "Child 3", ...},
]
}
Note:
Every data item needs to have an ID. Your example does not mention ID anywhere.
This example roughly follows the guidelines in http://jsonapi.org/ but you are free to follow whatever works for you, as long as you document it for the team.
This example attempts to load the actual data in response.data object, and side-loads children data in response.included array, thus keeping parent and child separate. You need to handle this response convention in Vue.js, preferably using Vuex as the store.
If you intend to follow this example, you also need to make sure the child API endpoints are active and can be independently accessed. This is helpful if your Vue App is loaded directly with child URL.
Sample child API endpoint:
www.example.com/api/parent/parent_id/child/child_id (if child_id is NOT unique)
www.example.com/api/child/child_id (if child_id is unique)
Did you mean component with is?
<component :is="componentType"></component>
This is the dynamic components feature of Vue.js
A very simple example: http://codepen.io/CodinCat/pen/ZLjrRX?editors=1010
see the document here: https://v2.vuejs.org/v2/guide/components.html#Dynamic-Components