Angular-2 : Change favicon icon as per configuration

前端 未结 6 1631
你的背包
你的背包 2021-01-31 09:53

I am rendering a dynamic page, menu and other items in my application. I also want to change favicon as per configured by admin.

Say, for example, if when my pag

6条回答
  •  野性不改
    2021-01-31 10:28

    We have nodejs running in the back-end, we have URL specific favicon to display as a requirement.

    In app.js we implemented a resolveConfig() function which will help us to get the url specific configuration.

    The return value of above function is used in get favicon call as below.

    app.js

    app.get('/favicon.ico',(req,res)=> {
       let key = resolveConfig(req.hostname);
       switch (key) {
         case 'a':
           res.sendFile(__dirname + '/dist/assets/a.ico');
           break;
         case 'b':
           res.sendFile(__dirname + '/dist/assets/b.ico');
           break;
       }
    });
    

    index.html

    
    

    *this might be useful if you have a nodejs in backend.

提交回复
热议问题