regularjs / regular-state Goto Github PK
View Code? Open in Web Editor NEWregular router based on stateman
Home Page: http://regularjs.github.io/regular-state/
License: MIT License
regular router based on stateman
Home Page: http://regularjs.github.io/regular-state/
License: MIT License
regular可以支持到ie6,regular-state可以吗
是这样的情况:
const router = Restate({routes: {
'app': {
url: '',
view: Application
},
'app.introduce':{
url: '',
view: Introduce
},
'app.view': {
view: View
}
})
默认是会跳转到 app.introduce, 但如果因为某些条件的需要比如恢复上次的状态, 这个时候就不需要先转到app.introduce, 有没有方法可以直接启动就跳转到app.view.
如果在初始化后直接调用: router.go("app.view") 会出现app里的共有模板出现双份复制的情况
//登录
$http.post('/api/v1.0/sessions', {username: username, password: password, rememberMe: rememberMe}, (rep)->
data.ferror = false
data.loading = false
#返回的user数据
$state.user = rep
try
localStorage.setItem('username', username)
//把菜单权限存到localStorage
localStorage.setItem("permissions", stateman.user.permissions)
catch e
data.password = null
component.$update()
#跳转
$state.go("app.order");
)
//app模块的菜单数据 菜单组件 <app-menu ref="appMenu" menus={menus} state={@(this.$state)}></app-menu>
config: (data)->
data.menus = [
{url: '/', name: '首页', icon: 'home', state: 'app.index'}
]
try
permissions = localStorage.getItem("permissions")
catch e
if permissions
permissions=permissions.split(",")
for permission in permissions
switch permission
when 'P_ORDER' then data.menus.push({url: '/order', name: '订单', icon: 'table', state: 'app.order'})
when 'P_SALE' then data.menus.push({url: '/sale', name: '销售', icon: 'strikethrough', state: 'app.sale'})
when 'P_FINANCE' then data.menus.push({url: '/finance', name: '财务', icon: 'yen', state: 'app.finance'})
when 'P_SETTING' then data.menus.push({url: '/setting', name: '设置', icon: 'configure', state: 'app.setting'})
如题
因为微前端方案需要做成应用可插拔,所以产生了需要卸载路由的需求。
尝试使用stop
方法卸载:
stateman
提供了 stop
方法,但是该方法只卸载了内部histery
, 组件依然在内存中,所以组件的destroy
方法不会触发, 导致应用无法卸载干净,对于全局对象的事件没能及时销毁。
所以希望能够提供一种能够销毁方案来销毁整个应用, 例如在 https://github.com/regularjs/regular-state/blob/master/src/client.js#L157 这里新增一个 destroy 的生命周期,并重载 stateman 的 stop 方法调用 destroy 实现。
比如组件
const Component = Regular.exnted({
name: 'Component',
template: `
<div r-view > Nest Component with r-view </div>
`
})
const Module = Regular.extend({
template: `
<Component />
`
})
这个Module
作为路由模块,这个r-view就不生效了
低版本Regular没有这个API, 需要做判断.
if(!Regular.isRegular){
Regular.isRegular = function( Comp ){
return Comp.prototype instanceof Regular;
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.